简体   繁体   中英

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

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

您没有看到此消息的原因是您从该页面进行导航,因此永远不会呈现注入了此脚本的页面。

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";

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';
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM