.Net Links

Thursday, February 3, 2011

Execute JavaScript function from ASP.NET codebehind


Simple example of Calling a JavaScript function from codebehind is given below.



In order to call it from code behind, use the following code in your Page_Load

C#

protected void Page_Load(object sender, EventArgs e)
{
if (!ClientScript.IsStartupScriptRegistered("alert"))
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "alertMe", "javascript:alertMe(This is Sample JS Testing); ", true);
}
}

Labels: