Calling a javascript function from Page_Load in code-behind

后端 未结 8 1202
广开言路
广开言路 2021-01-25 03:49

How can I call a javascript function, that is in the aspx page, from the Page_Load method, in the code-behind?

相关标签:
8条回答
  • 2021-01-25 04:17

    The easiest way is to use the page's ClientScript property. You can register some code to run when the page loads using something like

    ClientScript.RegisterStartupScript(GetType(), "hiya", "alert('hi!')", true);
    

    See http://msdn.microsoft.com/en-us/library/asz8zsxy.aspx for more info.

    This should be available from a child control by tacking "Page." onto the beginning of the code above.

    0 讨论(0)
  • 2021-01-25 04:17

    Please try this code:

      ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "MyFun1", "test();", true);
    
    0 讨论(0)
提交回复
热议问题