Click here to Skip to main content
12,299,256 members (58,193 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB ASP.NET VB.NET
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
Posted 23-Dec-12 10:49am
conanzz307
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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi,

Please try to trim the Text and test it out.

Good luck.

Regards,
Vamsi
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Try it
If txtUserName.Text.Trim() Like "Adm_?" Then
            Response.Redirect("AdminLoggedIn.aspx")
        Else
            Response.Redirect("LoggedIn.aspx")
        End If
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

use code like--
if(txtUserName.Text.Contains("Adm_?"))
{
  Response.Redirect("AdminLoggedIn.aspx")
}
else
{
  Response.Redirect("LoggedIn.aspx")
}
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

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...
If Ucase(Mid(txtUserName.Text, 1, 5)) Like "ADM_?" Then
    Response.Redirect("Address1")
Else 
    Response.Redirect("Address2")
End IF

Accept Solution if it works...
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

Refer this similar thread on CP
Like operator in conents in C#.net[^]
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 7

Try(if case-sensitivity is not a concern for your condition):
If txtUserName.Text.Trim().ToLower() Like "adm_?" Then
            Response.Redirect("AdminLoggedIn.aspx")
        Else
            Response.Redirect("LoggedIn.aspx")
        End If
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100