0

I have two pages. The first page is a registration page where the user creates a user name and password. The second page is a log in page, where the user enters their user name and password. I want to use CompareValidator to make sure the user name and password match the credentials that they created. I thought that I could call the TextBox from the registration page, in my ControlToCompare:

//TextBoxLogIn is from the first page
<asp:CompareValidator ID="CompareValidatorUserName" runat="server" ErrorMessage="Wrong User Name" ForeColor="Red" ControlToCompare="TextBoxLogIn" ControlToValidate="TextBoxUserName"></asp:CompareValidator>

I can't seem to be able to find anything on this specific issue. Does anyone have any suggestions on how this can be done?

Bob
  • 91
  • 1
  • 1
  • 9
  • 1
    No you can't take the `TextBoxLogIn` from the first page. And for authentication you dont have to do a client-side `CompareValidator` type of thing. You may validate the user's login info on server-side i.e. in code behind – shahsani Oct 15 '17 at 19:20
  • #shahsani, I understand that I could do it from the server side, but can you call information from a textbox from a previous page, in CompareValidator? – Bob Oct 15 '17 at 19:25
  • No you can't access a previous page's field in current page! – shahsani Oct 15 '17 at 19:25
  • 1
    If user's registration is successful then during login username and password should be validated against database . Even if you can access previous page control, it's not recommended to compare against them for validating user for login. – Chetan Oct 15 '17 at 19:25

1 Answers1

0

This is a classic behaviour of http - it is stateless i.e., once response is sent, the transaction is complete and gone.

It is the server or the client(your browser) which has to keep the track of data.

So to access page 1's data from page 2, first store page 1's data somewhere - either the browser's cache or server's session variable.

BUT

I would never store passwords anywhere other than LDAP servers - even there the passwords are encrypted and then stored.

Browser: Local Storage vs Cookies

Server: https://msdn.microsoft.com/en-us/library/75x4ha6s.aspx

Shree Harsha
  • 377
  • 3
  • 9