How to execute javascript code from code behind file in asp.net (c#) on button click(not placed under update panel).

Aman Sharma
0

You can use following function to execute javascript code from code behind file in asp.net using c#.

 

**when you are not using ajax update panel.

 

public void ExecuteJavascriptCode(System.Web.UI.Page zpage, string javaScriptCode)

        {

 

            string alertScript = "<script language=\"javascript\" type=\"text/javascript\">";

 

            alertScript += javaScriptCode;

 

            alertScript += "</script>";

 

 

 

            if (!zpage.IsClientScriptBlockRegistered("alert"))

                zpage.RegisterClientScriptBlock("alert", alertScript);

 

        }

 


In alert function we are using

zpage.RegisterClientScriptBlock(string key, string script).

 

Here zpage is object of type class System.Web.UI.Page.

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !