javascript alert function

K

Kenneth

Hi,

In a document I have three lines that detects and
redirects to another page is a session variable is 0

If Session("Customer_ID")=0 Then
Response.Redirect("myPage.aspx")
End If

What I really would like to have is a notification for the
users what happened before they were redirected and in
traditional asp I used the javascript alert function, but
how does the code go to implement this in asp.net above
the line Response.Redirect("myPage.aspx")?

TIA

/Kenneth
 
C

Chris Jackson

You have to be mindful of where your code is running when you are using
ASP.NET. In your example, since you are using the Session object, you are
running on the server. Your web server has no way of popping up an alert
dialog on the user's machine. Instead, it has to write JavaScript code to
the client, which can then execute this code and give the user an alert. So,
you need to change your approach. If you need the alert, you will need to
feed the information to the client, and have the entire check take place
there, in which case you lose access to your session variable (stored on the
server), so the only comparison you will be able to do is based on something
on that form or else something that you write out to the client machine.

If you want to get clever, it's also possible that you could redirect to a
new page that serves the same purpose as the alert - giving them a button to
proceed with the redirect, and a button that just executes a history.back
script to bring the user back to the previous page.
 
K

Kenneth

Chris,

With all respect, in an oldfashioned .asp file I have the
following code:

<% if Session("UserName") = "" then %>
<script language="javascript">
alert('Session Timeout has expired. You
have to log in again!');
top.location.href = "login.asp";
</script>
<% end if%>

It also runs on the server.

Can't I use the Page 'RegisterStartupScript' method to
achive the same effect?

/Kenneth
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top