Tutorial :Register javascript code from serverside


I have a Asp.Net control inside a updatepanel thet is inside a modal popup. I wont to register write javascript code in client from the control code.

these is my code:

Dim output As String = .. javascript code  Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "frmulaMatrix", output, True)  

these is my second thinf but dont work

Page.RegisterClientScriptBlock("SCRIPTNAME", "<script language='javascript'>" + output+"</script>")  


You must be trying to do this within a partial post back.

You should do it like this.

  ScriptManager scriptManager = ScriptManager.GetCurrent(Page);    if (scriptManager != null && scriptManager.IsInAsyncPostBack)    {      //if a MS AJAX request, use the Scriptmanager class      ScriptManager.RegisterStartupScript(Page, Page.GetType(), scriptKey, script, true);    }    else    {      //if a standard postback, use the standard ClientScript method      Page.ClientScript.RegisterStartupScript(Page.GetType(), scriptKey, script, true);    }  


The second method is deprecated. Where in the page life cycle are you calling this code?


try without the script tags. I believe the script manager adds that automatically

script = @"function onBeginRequest myJavascript{  //bla bla                          }                      this.Page.ClientScript.RegisterStartupScript(this.GetType(), "frmulaMatrix", script, true);  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »