By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,016 Members | 2,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,016 IT Pros & Developers. It's quick & easy.

javascript alert function

P: n/a
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
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows XP
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Kenneth" <ke***********@chello.se> wrote in message
news:09****************************@phx.gbl...
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

Nov 17 '05 #2

P: n/a
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
-----Original Message-----
You have to be mindful of where your code is running when you are usingASP.NET. In your example, since you are using the Session object, you arerunning on the server. Your web server has no way of popping up an alertdialog on the user's machine. Instead, it has to write JavaScript code tothe 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 tofeed the information to the client, and have the entire check take placethere, in which case you lose access to your session variable (stored on theserver), so the only comparison you will be able to do is based on somethingon 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 anew page that serves the same purpose as the alert - giving them a button toproceed with the redirect, and a button that just executes a history.backscript to bring the user back to the previous page.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows XP
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Kenneth" <ke***********@chello.se> wrote in message
news:09****************************@phx.gbl...
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

.

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.