conditional javascript in asp.net

Discussion in 'ASP .Net' started by Zdenko Rupcic, Sep 21, 2006.

  1. I want to add a javascript which would execute only if certain
    requirements are met.
    Example:
    If user isn't logged in, a message box would pop up, telling the user he
    has to log in, but if the user is already logged in, there would be no message.

    In classical asp, I would do it like this:

    <body<% IF LEN(Session("username"))=0 THEN Response.Write " onLoad=""alert('You need to log in for more info!')""" %>>

    How to do that in asp.net, using .vb code? I know how to add javascript events for controls, but not for the page body.
     
    Zdenko Rupcic, Sep 21, 2006
    #1
    1. Advertising

  2. You could use RegisterClientScript. Wrap the register around a
    conditional to test if they are logged in. Here is a thread with an
    example of how to use this:

    http://groups.google.com/group/micr...=RegisterClientScript&rnum=5#97f6aa687001c3b4

    hope this helps!

    Sean

    Zdenko Rupcic wrote:
    > I want to add a javascript which would execute only if certain
    > requirements are met.
    > Example:
    > If user isn't logged in, a message box would pop up, telling the user he
    > has to log in, but if the user is already logged in, there would be no message.
    >
    > In classical asp, I would do it like this:
    >
    > <body<% IF LEN(Session("username"))=0 THEN Response.Write " onLoad=""alert('You need to log in for more info!')""" %>>
    >
    > How to do that in asp.net, using .vb code? I know how to add javascript events for controls, but not for the page body.
     
    Sean Chambers, Sep 21, 2006
    #2
    1. Advertising

  3. Zdenko Rupcic, Sep 22, 2006
    #3
  4. Sean Chambers, Sep 22, 2006
    #4
    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. jurujuba
    Replies:
    3
    Views:
    1,583
    Eliyahu Goldin
    Feb 20, 2005
  2. Hossein Farkho
    Replies:
    1
    Views:
    507
    Karl Seguin
    Nov 30, 2005
  3. Replies:
    3
    Views:
    42,628
  4. Alec S.
    Replies:
    10
    Views:
    10,333
    Alec S.
    Apr 16, 2005
  5. Brian

    ASP.NET Conditional Statements

    Brian, Jul 20, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    1,148
Loading...

Share This Page