0

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 call a javascript function on the page?

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

2 Answers 2

1

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

ScriptManager.RegisterStartupScript(UP1, UP1.GetType(), "alertHi", "alert('hi');", true);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I thought it would be harder than this. Is this the best way to do this or should it be a javascript event on the control?
1

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>");
   }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.