1

I have this code on the OnClick event of a Button:

if (true) {
  ClientScript.RegisterStartupScript(UpdatePanel1.GetType(), "", "show_modal('true');", true);
} else {
  ClientScript.RegisterStartupScript(UpdatePanel1.GetType(), "", "show_modal();", true);
}

And I define the Button as a trigger for an UpdatePanel:

<Triggers>
  <asp:AsyncPostBackTrigger ControlID="btnEdit" EventName="Click" />
</Triggers>

The function show_modal is located into a .js file which is included into the ASP page.

How can I make this script works?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Soufiaane
  • 1,737
  • 6
  • 24
  • 45
  • take a look at: http://stackoverflow.com/questions/3341623/asp-net-updatepanel-in-gridview-jquery-datepicker/3341741#3341741 http://stackoverflow.com/questions/13890391/asp-net-web-application-jquery-photoviewer-and-ajaxical-update/13890462#13890462 http://stackoverflow.com/questions/13856717/jquery-accordion-not-re-initiating-after-an-asp-net-postback/13856997#13856997 – Aristos Dec 18 '12 at 17:02
  • [similar question](http://stackoverflow.com/questions/2864398/javascript-code-inside-updatepanel) - [other similar question](http://stackoverflow.com/questions/487269/registering-a-dynamic-javascript-after-an-updatepanels-update) - [and other similar question](http://stackoverflow.com/questions/7844061/running-javascript-after-update-panel-refresh) – adripanico Dec 19 '12 at 10:16

1 Answers1

2

Do not use ClientScript.RegisterStartupScript. Use ScriptManager1.RegisterStartupScript instead. Where "ScriptManager1" is the name of your ScriptManager control.

Yuriy Galanter
  • 38,833
  • 15
  • 69
  • 136
  • 1
    It's not `ScriptManager1`, it's just `ScriptManager`. `RegisterStartupScript` is a shared function (ie: a class method, not an instance one) of `ScriptManager` class. – adripanico Dec 18 '12 at 23:05
  • What about when you need to write a generic method that would run on any page? http://codecorner.galanter.net/2011/03/03/run-javascript-from-both-full-and-partial-asp-net-postback/ – Yuriy Galanter Dec 20 '12 at 16:04