Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
it always go with else, even if txtUserName.Text = "Adm_A" Why is that ?

SQL
If txtUserName.Text Like "Adm_?" Then
            Response.Redirect("AdminLoggedIn.aspx")
        Else
            Response.Redirect("LoggedIn.aspx")
        End If
Posted
Comments
André Kraak 23-Dec-12 17:09pm    
I tried If "Adm_A" Like "Adm_?" Then and it works.
Try debugging and see what the actual contents of txtUserName.Text is.
Ashok19r91d 24-Dec-12 2:00am    
What's the Length of txtUserName?
if the Text in txtUserName is "Adm_A" then If condition Works
If the Text in txtUserName is "Adm_As" then If condition will not work...
André Kraak 24-Dec-12 14:01pm    
The '?' indicates that you except one character, if you want to except zero or more use '*' instead.

Hi,

Please try to trim the Text and test it out.

Good luck.

Regards,
Vamsi
 
Share this answer
 
Try it
VB
If txtUserName.Text.Trim() Like "Adm_?" Then
            Response.Redirect("AdminLoggedIn.aspx")
        Else
            Response.Redirect("LoggedIn.aspx")
        End If
 
Share this answer
 
use code like--
if(txtUserName.Text.Contains("Adm_?"))
{
  Response.Redirect("AdminLoggedIn.aspx")
}
else
{
  Response.Redirect("LoggedIn.aspx")
}
 
Share this answer
 
Try this, I hope this will help you...

As long as I Check this IF condition is Length and Case Sensitive,
* "?" accepts only 1 Character when Matching
* "Adm" is not Equal as "ADM" or "adm".

By Subjecting these limitation my solution is here...
VB
If Ucase(Mid(txtUserName.Text, 1, 5)) Like "ADM_?" Then
    Response.Redirect("Address1")
Else 
    Response.Redirect("Address2")
End IF


Accept Solution if it works...
 
Share this answer
 
As we know in VB.Net, LIKE operator with ? sign only takes single character(Any single character). And you are giving more than one extra character in that.

Refer the link below for more explanation in like operator.
Like Operator (Visual Basic)[^]


--Amit
 
Share this answer
 
Refer this similar thread on CP
Like operator in conents in C#.net[^]
 
Share this answer
 
Try(if case-sensitivity is not a concern for your condition):
VB
If txtUserName.Text.Trim().ToLower() Like "adm_?" Then
            Response.Redirect("AdminLoggedIn.aspx")
        Else
            Response.Redirect("LoggedIn.aspx")
        End If
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900