开发者

Display modal after postback without ASP.NET Ajax

开发者 https://www.devze.com 2023-01-11 23:24 出处:网络
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

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 with开发者_StackOverflowout ASP.NET Ajax. just jQuery? I basically want to run some javascript after the server side click code runs, after the postback.


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.


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.

0

精彩评论

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