javascript alert function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kenneth

    #1

    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("Custom er_ID")=0 Then
    Response.Redire ct("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.Redire ct("myPage.aspx ")?

    TIA

    /Kenneth
  • Chris Jackson

    #2
    Re: javascript alert function

    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" <kenneth.philp@ chello.se> wrote in message
    news:09e901c3a3 08$d6d49df0$a00 1280a@phx.gbl.. .[color=blue]
    > Hi,
    >
    > In a document I have three lines that detects and
    > redirects to another page is a session variable is 0
    >
    > If Session("Custom er_ID")=0 Then
    > Response.Redire ct("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.Redire ct("myPage.aspx ")?
    >
    > TIA
    >
    > /Kenneth[/color]


    Comment

    • Kenneth

      #3
      Re: javascript alert function

      Chris,

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

      <% if Session("UserNa me") = "" then %>
      <script language="javas cript">
      alert('Session Timeout has expired. You
      have to log in again!');
      top.location.hr ef = "login.asp" ;
      </script>
      <% end if%>

      It also runs on the server.

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

      /Kenneth
      [color=blue]
      >-----Original Message-----
      >You have to be mindful of where your code is running when[/color]
      you are using[color=blue]
      >ASP.NET. In your example, since you are using the Session[/color]
      object, you are[color=blue]
      >running on the server. Your web server has no way of[/color]
      popping up an alert[color=blue]
      >dialog on the user's machine. Instead, it has to write[/color]
      JavaScript code to[color=blue]
      >the client, which can then execute this code and give the[/color]
      user an alert. So,[color=blue]
      >you need to change your approach. If you need the alert,[/color]
      you will need to[color=blue]
      >feed the information to the client, and have the entire[/color]
      check take place[color=blue]
      >there, in which case you lose access to your session[/color]
      variable (stored on the[color=blue]
      >server), so the only comparison you will be able to do is[/color]
      based on something[color=blue]
      >on that form or else something that you write out to the[/color]
      client machine.[color=blue]
      >
      >If you want to get clever, it's also possible that you[/color]
      could redirect to a[color=blue]
      >new page that serves the same purpose as the alert -[/color]
      giving them a button to[color=blue]
      >proceed with the redirect, and a button that just[/color]
      executes a history.back[color=blue]
      >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" <kenneth.philp@ chello.se> wrote in message
      >news:09e901c3a 308$d6d49df0$a0 01280a@phx.gbl. ..[color=green]
      >> Hi,
      >>
      >> In a document I have three lines that detects and
      >> redirects to another page is a session variable is 0
      >>
      >> If Session("Custom er_ID")=0 Then
      >> Response.Redire ct("myPage.aspx ")
      >> End If
      >>
      >> What I really would like to have is a notification for[/color][/color]
      the[color=blue][color=green]
      >> users what happened before they were redirected and in
      >> traditional asp I used the javascript alert function,[/color][/color]
      but[color=blue][color=green]
      >> how does the code go to implement this in asp.net above
      >> the line Response.Redire ct("myPage.aspx ")?
      >>
      >> TIA
      >>
      >> /Kenneth[/color]
      >
      >
      >.
      >[/color]

      Comment

      Working...