开发者

Call javascript on page from ASP.Net User Control Event

I have a aspx page containing a user control (inside an UpdatePanel), the page subscribes to an event raised by a button click on the control.

Is it possible to开发者_StackOverflow call a javascript function on the page?

void control1_Edit(object sender, EventArgs e)
{
   // Call client-side javascript function here
}


You can use ScriptManager.RegisterStartupScript - this is specifically for usage within an updatepanel.

ScriptManager.RegisterStartupScript(UP1, UP1.GetType(), "alertHi", "alert('hi');", true);


Use the ClientScript.RegisterClientScriptBlock method.

void control1_Edit(object sender, EventArgs e)
{
   if (!Page.ClientScript.IsClientScriptBlockRegistered(GetType(), "myScript"))
   {
      Page.ClientScript.RegisterClientScriptBlock(GetType(), "myScript", "<script>alert('hello world');</script>");
   }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜