Friday, 15 July 2011

alert not working before re-direction asp.net web application -



alert not working before re-direction asp.net web application -

in asp.net web application, trying simple operation. 1. bring alert "saved successfull" using page.registerclientscriptblock code behind. seems work fine. 2. after message, when seek add together response.redirect different page, above alert fails. redirection happen out alert.

i have tested script separately , works fine. issue is, if redirect, redirect happens out alert.

i tried move alert code behind jquery ( calling jquery function first alerts , window.location.href. not work.

is because redirection faster time taken alert come up? how can solve issue? out of box ideas welcome.

try this:

<script type="text/javascript"> function displayalertandredirect() { alert("save successful"); location.href = "/default2.aspx"; } </script> <asp:button runat="server" id="btnsave" text="save , redirect" onclick="btnsave_click"/>

and in code-behind:

protected void btnsave_click(object sender, eventargs e) { if (!page.clientscript.isstartupscriptregistered(typeof (page), "saveandredirect")) { page.clientscript.registerstartupscript(typeof (page), "saveandredirect", "displayalertandredirect();", true); } }

just tested , works charm :)

asp.net alert response.redirect

No comments:

Post a Comment