开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜