Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alert Before Redirect

Status
Not open for further replies.

byrne1

Programmer
Aug 7, 2001
415
US
Is there a way to display a java alert before redirecting to another page? I have code that should display an alert and then redirect the user to another page, but the redirect function fires before the alert pops up (if I have the redirect function commented out then the alert shows up just fine but of course the page stays put).

Any ideas?


.
.
.
Dim scriptString As String
scriptString = &quot;<script language=JavaScript> &quot; + Environment.NewLine
scriptString += &quot;alert('Transactions were successfully created!');&quot; + Environment.NewLine
scriptString += &quot;<&quot;
scriptString += &quot;/&quot;
scriptString += &quot;script>&quot;
If Not IsStartupScriptRegistered(&quot;Startup&quot;) Then
RegisterStartupScript(&quot;Startup&quot;, scriptString)
End If
Response.Write(scriptString)
Response.Redirect(&quot;main.aspx&quot;)
 
Hey Byrne1,

An ASP redirect will fire first because it is done server side rather than client side.. If you want this to be done properly, you will have to do the redirect with Javascript:

ie:

Dim scriptString As String
scriptString = &quot;<script language=JavaScript> &quot; + Environment.NewLine
scriptString += &quot;alert('Transactions were successfully created!');&quot; + Environment.NewLine
scriptString += &quot;self.location.href = 'main.aspx';&quot;
scriptString += &quot;<&quot;
scriptString += &quot;/&quot;
scriptString += &quot;script>&quot;
If Not IsStartupScriptRegistered(&quot;Startup&quot;) Then
RegisterStartupScript(&quot;Startup&quot;, scriptString)
End If
Response.Write(scriptString)


Hope this helped,

Cheers....

G.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top