开发者

Asp.net: How to call a javascript function at the end of button click code behind

开发者 https://www.devze.com 2023-01-19 17:37 出处:网络
My motto is to call a Java script function at the end of button click code behind. ie, firstly i need to execute the server side function after which my java script function should get invoked.

My motto is to call a Java script function at the end of button click code behind. ie, firstly i need to execute the server side function after which my java script function should get invoked.

My server side method is as follows

protected string SaveEmbedURL_click()

{

    if (txtembedurl.Text != null)
    {
        School aschool = new School();
        aschool.SchoolId = CurrentSchool.SchoolId;
        aschool.EmbedUr开发者_StackOverflow社区l = txtembedurl.Text;
        SchoolRespository.updateEmbedUrl(aschool);
        return "true";
    }

}

My Java script function is as follows

function SaveEmbedUrlClientSide() {

admin_CustomizeTheme.SaveEmbedURL_click(true);
$('#lbl_embedcode').removeClass('hide').addClass('show');
$('#embedCode').removeClass('hide').addClass('show');
CopyToClipboard("embedCode");

}

How can i achieve this?

Thanks.


I'm pretty sure all you need is to add this

RegisterStartupScript("YourJavaScript", "SaveEmbedUrlClientSide()");

"YourJavaScript" is an arbitrary string that is used to identify the Javascript.

Here's the relevant MSDN article.


Page.RegisterStartupScript is now obsolete, so I would use this code.

ClientScript.RegisterStartupScript(Page.GetType, "Javascript", "SaveEmbedUrlClientSide();", true);

RegisterStartupScript requires Type, Reference, Code, render script blocks. Reference Here

0

精彩评论

暂无评论...
验证码 换一张
取 消