开发者

Javascript popup Messagebox not working when we use Response.Redirect on ASP.NET Page?

开发者 https://www.devze.com 2022-12-21 01:40 出处:网络
I have update button and after saving the record to database, I am displaying popup Msg using Javascript as below.

I have update button and after saving the record to database, I am displaying popup Msg using Javascript as below.

When i don't use Response.Redirect, Popup is working fine. But when i 开发者_开发技巧use Response.Redirect, Popup is not displaying.

Anybody faced the same issue. Please throw some light.

Appreciate your help.

ScriptManager.RegisterStartupScript(
                this,
                typeof(string),
                "popup",
                "alert('Thank you for visiting the MedInfo website. Your request has been submitted.');",
                true);
            Response.Redirect("Default.aspx");


Create a js function , in function show message then navigate to the page

Server side

ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "ShowMessage()", true);

JS

function ShowMessage()
{
      alert('your message');
      window.location.href='default.aspx';
}


The very reason you don't see the message is that you navigate from this page, so the page with this script injected in it never gets rendered.


Response.Redirect transfers the control to another page, and your script is loaded in the current page.

See Response.Redirect Method

Remove the response.redirect method and then change the scriptmanager. Remove the alert message and instead call a javascript function. Inside the function you can show the alert message and then on the next line write

document.location = "Default.aspx";


ScriptManager.RegisterStartupScript(
                this,
                typeof(string),
                "popup",
                "alert('Thank you for visiting the MedInfo website. Your request has been submitted.')" + "location.href='Default.aspx';",true);


As mentioned earlier, Response.Redirect interrupt current page execution and transfers control to another page. If you want to show message box after redirect, register your javascript code in Page_Load event handler routine of page to which you are redirect.


Instead of doing a server side, try doing it in the client side. Add window.top.location ="Default.aspx" to your javascript code

0

精彩评论

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

关注公众号