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
精彩评论