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>");
}
}
精彩评论