views:

602

answers:

6

Hi

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");
+2  A: 

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.

Victor
Then, what is the resolution? How can i display the message?
Rita
Don't think you can achieve that using this method. I would use Page.ClientScript.RegisterOnSubmitStatement(this, typeof(string), "popup", "alert('Thank you for visiting the MedInfo website. Your request has been submitted.');", true); on your page load instead, so it would run when you click your button
Victor
+2  A: 

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";
rahul
Hmm.... wondering what is the alternative?
Rita
+1  A: 

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.

Gopher
+1  A: 

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

ram
Thanks Ram. I will try this.
Rita
+1  A: 

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';
}
Priyan R
A: 

hey may someone help me here i want to display an alert message box when i debagg default.aspx using vb 2005...this should be without the use of button

Mex