Show Alert Box and then Redirect

K

Kuldeep

Framework: Visual Studio 2005
Technology: ASP.NET 2.0
Language: C#.NET 2.0

Hi All,

I have an event procedure as shown below.

protected void lnkBtSendEmail_Click(object sender, EventArgs e)

{

FillVariables();

GenerateDataShuttle();

ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script
language='JavaScript'>alert(ABCDEFGH');</script>");

Response.Redirect("Default.aspx");

}

This piece of code will not allow the Javascript function to show the
"Alert" box to pop-up. The reason being, there is a Response.Redirect
happening soon after the ClientScript.RegisterStartupScript.

Now, if I comment the Response.Redirect line, the alert box pops up and
shows up the message (ABCDEFGH).

How do I show the Alert Box first and then redirect to any page?

Thanks in advance,

Kuldeep
 
A

Aidy

You need to do the redirect in your javascript also.

alert ('ABCDEFGH'); window.location.href = 'newpage.aspx';
 
K

Kuldeep

ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script
language='JavaScript'>alert('ABCDEFGH'); window.location.href =
'Default.aspx';</script>");

Oops that should work!
 
M

Mark Rae [MVP]

ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script
language='JavaScript'>alert('ABCDEFGH'); window.location.href =
'Default.aspx';</script>");

ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp",
"alert('ABCDEFGH'); window.location.href = 'Default.aspx';", true);

Then you don't need to worry about using deprecated <script> tags...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Alert box doesn't appear 6
conditionally run Javascript alert 2
Alert message not shown 3
Alert???? 28
ASP.NET message box 4
Alert() doesn't. Why? 31
Alert in Ajax 0
URGENT - Show message and redirect to a page 4

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top