views:

45

answers:

3

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>")
+2  A: 

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);
  }
Ismail
+1  A: 

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

matt-dot-net
A: 

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);
ftnilsson
Do you know what have you written? I think somewhere you have not formatted your answer properly
Ismail