Alert box doesn't appear

J

Jan

Hi,

Why don't i see the Alert box? The page is redirected without showing it. I
also tried with parameter 'False' and 'True'.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim a As Integer
a = 5
If a = 5 Then
Dim jv As String
jv = "<script language='javascript'>" _
& " alert(this is ok);" _
& "</script>"
Response.Write(jv)
Response.Redirect(next.aspx")
'Response.Redirect(next.aspx", False)
'Response.Redirect(next.aspx", True)
End If
End Sub

Thanks
Jan
 
J

Jan

Yes you're right, wrong copy of code, but that's not the problem.
In my code, there are quotes and i can't see the Alert box (without quotes,
i would get a java-error).
If i suppress the line with : " Response.Redirect(next.aspx")", i see that
Alert box ...

Why not with the Response.redirect?
(i tried with server.transfer and this works!)


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim a As Integer
a = 5
If a = 5 Then
Dim jv As String
jv = "<script language='javascript'>" _
& " alert('this is ok');" _
& "</script>"
Response.Write(jv)
Response.Redirect(next.aspx")
'Response.Redirect(next.aspx", False)
'Response.Redirect(next.aspx", True)
End If
End Sub
 
D

Damien

Hi,

Why don't i see the Alert box? The page is redirected without showing it. I
also tried with parameter 'False' and 'True'.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim a As Integer
a = 5
If a = 5 Then
Dim jv As String
jv = "<script language='javascript'>" _
& " alert(this is ok);" _
& "</script>"
Response.Write(jv)
Response.Redirect(next.aspx")
'Response.Redirect(next.aspx", False)
'Response.Redirect(next.aspx", True)
End If
End Sub

Thanks
Jan

Okay,

When you send a normal GET/POST request to a server, it generates a
response which consists of headers and content. Part of the headers
for a normal response it a status code - 200. This tells the browser
that the response is normal, and that it should go ahead and use the
rest of the headers and the content to display the page to the user.

When you use Response.Redirect on the server, it changes that status
code that is sent back to the client to 302. This status code,
essentially, says "what you were asking for has temporarily moved to
this new location", and provides the location information (in this
case, next.aspx). The browser just goes right ahead and requests the
next page - it never receives/processes and content associated with
the old page.

If you want to have a message box and then navigate to the next page,
you can put the navigation step into the javascript. Just add
window.navigate('next.aspx') to your script.

Damien
 
M

Mark Rae

Why not with the Response.redirect?

Apologies - I didn't read your post properly...

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim a As Integer
a = 5
If a = 5 Then
Dim jv As String
jv = "<script language='javascript'>" _
& " alert('this is ok');window.location='next.aspx';" _
& "</script>"
Response.Write(jv)
End If
End Sub
 
J

Jan

Thnaks Mark, i knew that.

What i don't know is why it doesn't work with response.redirect? Is there a
specific reason for that?
As i said, it works also with Server.transfer ...Why?
Thanks
 
J

Jan

Ok thanks for explantion

Damien said:
Okay,

When you send a normal GET/POST request to a server, it generates a
response which consists of headers and content. Part of the headers
for a normal response it a status code - 200. This tells the browser
that the response is normal, and that it should go ahead and use the
rest of the headers and the content to display the page to the user.

When you use Response.Redirect on the server, it changes that status
code that is sent back to the client to 302. This status code,
essentially, says "what you were asking for has temporarily moved to
this new location", and provides the location information (in this
case, next.aspx). The browser just goes right ahead and requests the
next page - it never receives/processes and content associated with
the old page.

If you want to have a message box and then navigate to the next page,
you can put the navigation step into the javascript. Just add
window.navigate('next.aspx') to your script.

Damien
 

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

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top