Calling Javascript Function from Code behind in Asp.net




Hi Friends...
Today, I am going to explain the topic "Calling JavaScript Method from Code Behind" For Asp.net developers. And this code is supports all browsers. Now let's take each of these Steps one by one.




Add this script block in header part of aspx page:


Add this code block in body tag:

Add this code block in ASPX code behind(Button Click Event):
protected void btnJSformCS_Click(object sender, EventArgs e)
{

 if (!ClientScript.IsStartupScriptRegistered("JSfromCS"))
 {
     Page.ClientScript.RegisterStartupScript(this.GetType(),
             "JSfromCS", "CallJSfromCS();", true);
 }

}

Finally build the solution and check the output. That's it, I hope you like this article.

Thanks,
www.pioneerscode.com




 

© 2012 Pioneers Code All Rights Reserved Pioneers Code