views:

127

answers:

2

I have an ASP.NET button. When the button is clicked, I'd like a modal popup to display after the server-side code for the button runs. I don't want to use the ASP.NET Ajax control toolkit modal popup extender.

With ASP.NET Ajax, I can hook into the end request event. Is there a way to do this without ASP.NET Ajax. just jQuery? I basically want to run some javascript after the server side click code runs, after the postback.

+2  A: 

It depends on what method you intend to use to start the postback via jQuery. If you're going to use an async postback (like jQuery.ajax), you can just provide a method to call when the postback is complete. See http://api.jquery.com/jQuery.ajax/.

If you're just going to use the normal postback, you can use the Page.ClientScript.RegisterClientScriptBlock from your server-side method to register a script that will run after the postback completes.

Jason
+3  A: 

You can use ScriptManager.RegisterStartupScript() for this, something like this:

ScriptManager.RegisterStartupScript(MyUpdatePanel, GetType(), "post-load-script",
  "$(function() { $('#dialog').dialog(); });", true);

Then the request from the UpdatePanel comes back it would be running this:

$(function() { 
  $('#dialog').dialog(); 
});

You could of course put anything you wanted for script there, but if you simply used a Label or whatever in the #dialog <div> that populated as part of the update, this would show it (if you're using the jQuery UI dialog, there are others). The concept is very general, you're just registering some JavaScript to run when the async request comes back, which modal and how you want to do that is very open.

Nick Craver