Reputation: 51
it always go with else, even if txtUserName.Text = "Adm_A" Why is that ?
If txtUserName.Text Like "Adm_?" Then
Response.Redirect("AdminLoggedIn.aspx")
Else
Response.Redirect("LoggedIn.aspx")
End If
Upvotes: 2
Views: 116
Reputation: 1522
How about checking if it starts with the "Adm_" string:
If txtUserName.Text.StartsWith("Adm_") Then
Response.Redirect("AdminLoggedIn.aspx")
Else
Response.Redirect("LoggedIn.aspx")
End If
Upvotes: 0
Reputation: 216273
A simple console application to test your problem
Sub Main
Dim test = "Adm_AA"
CheckLike(test)
test = "Adm_A"
CheckLike(test)
test = "Adm_A " ' a space after the A'
CheckLike(test)
End Sub
Sub CheckLike(ByVal toCheck as string)
If toCheck Like "Adm_?" Then
Console.WriteLine("Matched")
Else
Console.WriteLine("Not Matched")
End If
End Sub
Results:
Not Matched
Matched
Not Matched
So there is something in your strings that it's not like you think it is. Use the debugger and verify the if statement and its argument. Also pay attention to the locale of the server where you run the webapp and the Option Compare used
Upvotes: 1
Reputation: 3591
can you try this
If txtUserName.Text.Trim() Like "Adm?" Then
Upvotes: 0
Reputation: 143
I believe that is because the question mark is a pattern operator. Please check http://msdn.microsoft.com/en-us/library/swf8kaxw(v=vs.71).aspx
Have you tried using contains instead of like?
Upvotes: 0