Link to home
Start Free TrialLog in
Avatar of jjrr007
jjrr007

asked on

Page Redirect After Clicking OK on Message Box

I am using he following code C# with a web form:

 if (result == 0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Error! Add New Item First!');", true);
      Response.Redirect("~/new.aspx");
            }

Open in new window


The issue I have is the page just redirects.  It doesn't first display the message box and then after I click OK, then redirect.
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try this it is working fine.

if (result == 0)
{
string message = "You will now be redirected to Google Home Page.";
    string url = "http://www.google.com";
    string script = "window.onload = function(){ alert('";
    script += message;
    script += "');";
    script += "window.location = '";
    script += url;
    script += "'; }";
    ClientScript.RegisterStartupScript(this.GetType(), "Redirect", script, true);
}

Open in new window

Avatar of jjrr007
jjrr007

ASKER

Thanks.  I tried this and thesame page refreshed- no message or page change.  Below is what I used:

  if (result == 0)
            {
string message = "Error! Add New Item First. Item Does Not Exist! Being Redirected";
                string url = "http://www.google.com";
                string script = "window.onload = function(){ alert('";
                script += message;
                script += url;
                script += "'; }";
                ClientScript.RegisterStartupScript(this.GetType(), "Redirect", script, true);
}

Open in new window


What do you suggest?
I take it you did not see my post?
Avatar of jjrr007

ASKER

Yes, I missed your comment Kaufmed.  It worked.  You are the best
Avatar of jjrr007

ASKER

Thank you for a correct, quick answer