string test difficulty asp.net

HOUSSEM MAHJOUBI 286 Reputation points
2021-01-19T13:10:55.307+00:00

H members
when i make a single test of string it work fine
user = HttpContext.Current.User.Identity.Name
Label7.Text = user

    If Not user = "STUPREMAT\M.houssem" Then
        Menu1.Items(2).Enabled = False
     End If

and when i make multiple test of string not work like this
user = HttpContext.Current.User.Identity.Name
Label7.Text = user
If Not Label2.Text = "STUPREMAT\B.Nizar" Or Not Label2.Text = "STUPREMAT\B.ATIK" Or Not Label2.Text = "STUPREMAT\M.houssem" Then
Menu1.Items(2).Enabled = False
End If
please help what is the problem

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,596 questions
{count} votes

Accepted answer
  1. HansV 966 Reputation points MVP
    2021-01-19T14:01:53.653+00:00
    1. You set the caption of Label7 to user, but then check Label2, not Label7.
    2. You should use And instead of Or. The Or condition will always evaluate to True.

    If Not Label2.Text = "STUPREMAT\B.Nizar" And Not Label2.Text = "STUPREMAT\B.ATIK" And Not Label2.Text = "STUPREMAT\M.houssem" Then

    Alternatively, place Not outside parentheses:

    If Not (Label2.Text = "STUPREMAT\B.Nizar" Or Label2.Text = "STUPREMAT\B.ATIK" Or Label2.Text = "STUPREMAT\M.houssem") Then


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.