Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to check and change labels and textboxes in ASP.net

I am trying to make a website using asp.net. First you must log in. This textbox is called "Username" and there is a textbox called "Password".

If Username = Hello and Password = 123 then I want the page to redirect. If it doesn’t match then I want a pre-existing label called "ErrorMessage" to display a message saying "Please check Username and password".

Here is my current code in the button click event.
Nothing works so far.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If (Username.Text.Contains("Hello")) & (Password.Text.Contains("123")) Then
            Response.Redirect("MemberContactInfo.aspx")
        Else
            ErrorMessage.Text = "Please check username and password"
        End If

>Solution :

You’re using the wrong operator in your If statement. When you want two conditions to be true, you should use the And operator, not the & operator (which performs string concatenation).

Modify your code as follows:

If (Username.Text.Contains("Hello")) And (Password.Text.Contains("123")) Then
    Response.Redirect("MemberContactInfo.aspx")
Else
    ErrorMessage.Text = "Please check username and password"
End If
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading