javascript alert function

Discussion in 'ASP .Net' started by Kenneth, Nov 4, 2003.

  1. Kenneth

    Kenneth Guest

    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
    Kenneth, Nov 4, 2003
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:09e901c3a308$d6d49df0$...
    > 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
    Chris Jackson, Nov 5, 2003
    #2
    1. Advertising

  3. Kenneth

    Kenneth Guest

    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 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" <> wrote in message
    >news:09e901c3a308$d6d49df0$...
    >> 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

    >
    >
    >.
    >
    Kenneth, Nov 5, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Erik Veldkamp
    Replies:
    2
    Views:
    21,936
    rogachez
    Jun 18, 2010
  2. Michelle Stone

    alert using Javascript with asp.net

    Michelle Stone, Dec 5, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    575
    Steven Alexander
    Dec 5, 2003
  3. Mersh
    Replies:
    0
    Views:
    477
    Mersh
    Mar 13, 2007
  4. Ganesh
    Replies:
    0
    Views:
    538
    Ganesh
    Jun 29, 2007
  5. Replies:
    3
    Views:
    280
    Laurent Bugnion
    Aug 24, 2006
Loading...

Share This Page