www.webdeveloper.com
Results 1 to 6 of 6

Thread: Weird ASP Session Issue

  1. #1
    Join Date
    Sep 2006
    Posts
    632

    Question Weird ASP Session Issue

    I have an ASP page which has this script at the top of the page:

    Code:
    <% if session("username") = "" then 
    response.redirect "notification.asp?error=notloggedin" 
    end if
    %>
    Which means the page needs a value in the session variable "username" else it would redirect to the "notification.asp" page. This works perfectly when I click on hyperlinks that points to the above page. But if I click on a button instead of a hyperlink then the session does not work. Any idea why?

    Code for Button:
    Code:
    <input type="button" value="Back To Home" OnClick="location.href='add-contact.asp';">


    Thanx

  2. #2
    Join Date
    Jan 2008
    Location
    Florida
    Posts
    1,227
    I don't see any reason why the session "does not work". What does the session variable become when using the location method?

  3. #3
    Join Date
    Sep 2006
    Posts
    632
    Quote Originally Posted by yamaharuss
    I don't see any reason why the session "does not work". What does the session variable become when using the location method?

    it becomes empty

  4. #4
    Join Date
    Jan 2008
    Location
    Florida
    Posts
    1,227
    Have you tested that the session variable exists on the form page?

  5. #5
    Join Date
    Sep 2006
    Posts
    632
    Yes it does

  6. #6
    Join Date
    Jan 2008
    Location
    Florida
    Posts
    1,227
    I think you need to double check that...

    here's a successful test, feel free to recreate it..

    a.asp
    Code:
    <% session("username") = "Russ" %> 
    <input type="button" value="Back To Home" OnClick="location.href='b.asp';">
    b.asp
    Code:
    <% Response.Write ("hello " &session("username")) %>
    The above works fine.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles