473,466 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

javascript alert function

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
2 2869
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gowhera Hussain | last post by:
Use This for Learning Only .... Do Not Try To Act Smart HACKING WITH JAVASCRIPT Dr_aMado Sun, 11 Apr 2004 16:40:13 UTC This tutorial is an overview of how javascript can be used to bypass...
1
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff...
11
by: Vincent van Beveren | last post by:
Hi everyone, I have the following code using inheritence The important part is the function getName(). The result should alert 'John Doe': function First(name) { this.name = name; ...
14
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net...
5
by: elsenraat_76 | last post by:
Hello! I was wondering if someone could help me out with a problem I'm having? I'm trying to input a javascript value into an anchor tag (from a function), but don't have an event to call the...
1
by: Jing You | last post by:
hi every one, I have got some confused problem when I try to write some custom object by javascript. Look at the example code here: <BODY> <script language="jscript">
9
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work...
7
by: julian.tklim | last post by:
Hi, I need to build an editable Datagrid with add & delete buttons on each row using javascript. DataGrid need not be pre-populated with values. To make the thing complicated, one of the...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
12
by: pantagruel | last post by:
Hi, I'm thinking of making a WScript based JavaScript library, I can think of some specific non-browser specific scripting examples that should probably make it in, like Crockford's little...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.