By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,162 Members | 1,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,162 IT Pros & Developers. It's quick & easy.

Stupid question about passing variables

P: n/a
Sorry for the stupid question but I cannot see what I am doing wrong. I found this code to password protect our ASP pages and it works fine but I am trying to pass a variable between pages so I get re-directed to the page I want. I just cannot figure out what I am doing wrong.
Here is the code at the top of the first page. I added the "?Page=linkspda.asp" part
Expand|Select|Wrap|Line Numbers
  1. <%
  2. If Session("BlnLoggedIn") <> True Then
  3. Response.Redirect("")
  4. End If
  5. %>
This does take me to the login.asp page and in the address bar on the browser it shows the ""
The login.asp page looks like this:

Expand|Select|Wrap|Line Numbers
  1. <% 
  2. Response.Expires = -1000 'Make sure the browser doesn't cache this page
  3. Response.Buffer = True 'enables our response.redirect to work
  4. %>
  6. <html>
  7. <head><title>Password Protect your ASP pages</title>
  8. </head>
  9. <body>
  11. <%
  12. If Request.Form("submit") ="Login" Then 
  13. CheckLoginForm
  14. Else
  15. ShowLoginForm 
  16. End If 
  17. %> 
  19. <%
  20. Sub CheckLoginForm
  21. testvar = Request.QueryString("Page")
  22. 'check if the value of the text field 'username' and 'password' are correct
  23. If Request.Form("username") = "test" AND Request.Form("password") = "pass" Then
  24. Session("BlnLoggedIn") = True
  25. Response.Redirect testvar
  26. Else
  27. Response.Write "<div align='center'>You are not logged in.</div><br>"
  28. ShowLoginForm 
  29. End If
  30. End Sub
  31. %> 
  33. <% Sub ShowLoginForm %>
  34. <div align='center'>
  35. <!-- start the HTML login form -->
  36. <form name="form" action="login.asp" method="post">
  37. <table>
  38. <tr>
  39.         <td><font size="8">User Name :</font></td>
  40.         <td><input type="text" style="font-size:48px" name="username"></td></tr>
  41. <tr>
  42.         <td><font size="8">Password : </font></td>
  43.         <td><input type="password" style="font-size:48px" name="password"></td></tr>
  44. <tr><td colspan="2"><input type="submit" style="font-size:48px" name="submit" value="Login"></td></tr>
  45. </table> 
  46. </form>
  47. <!-- end the HTML login form -->
  48. </div> 
  49. <% End Sub %> 
  51. </body>
  52. </html>
After the "Sub CheckLoginForm" I added the line:
testvar = Request.QueryString("Page")
Response.Redirect testvar

The Response.Redirect was just:
Response.Redirect "linkspda.asp"

The Request.QueryString("Page") does not seem to contain anything.

What am I doing wrong?

Sep 27 '10 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 164
When the user arrives at login.asp the Query String contains the Page variable. However, when the user submits the form, the Page variable is lost because it is not included in the querystring of the action attribute on the form. You need to include it as a querystring parameter in the action attribute of the form, or you need to include it as a hidden input element of the form; but, if you include it as a hidden element, you will have to test for it using Request.Form since you are using a POST operation.

I personally suggest you just pass it through the form as a hidden element, and change your test using the generic Request().
Sep 29 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.