Home > Mobile >  How to check and change labels and textboxes in ASP.net
How to check and change labels and textboxes in ASP.net

Time:01-21

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.

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

CodePudding user response:

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
  •  Tags:  
  • Related