Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
if (TXTSAVE.Text  == "False")
            {

                MessageBox.Show("You Do Not Have Permission");
                return;
            }



This Code Is Not Running
And TXTSAVE Have "False" Value
Posted
Updated 31-Jan-16 23:29pm
v2
Comments
CPallini 1-Feb-16 5:37am    
Your question is not clear. What do you want to do?
Da-broken-Breakpoint 2-Feb-16 1:30am    
"1. I did not ask this question.
2. If you need any clarifications, make use of comments section. Do not post that as solutions. " -Whoops my bad. I deleted it.

You should try to use conditions instead to check Member11280947. For example, have some validation routine and set a boolean flag to false/true based on it.
Anyway the solution to this is to either convert the input to upper or lower case and validate it accordingly or you could choose the inbuilt static method string.compare as listed in MSDN <https: msdn.microsoft.com="" en-us="" library="" zkcaxw5y(v="vs.110).aspx">.

This is definitely not a good way to check for permissions.

To compare the strings, you can make use of
C#
string.Compare(string1,string2,StringComparison.OrdinalIgnoreCase)
 
Share this answer
 
Text boxes are free-form user entry fields - so it is possible for a user to enter something not quite as you expected. And we, as humans, sometimes see what we expected, not what is really there. So...
1. Perhaps there are leading / trailing spaces
2. Perhaps you are seeing 'False' when in reality the text is 'false' (F vs f)

Try the following:

if (TXTSAVE.Text.Trim().Equals("False", StringComparison.InvariantCultureIgnoreCase))
    { 
    MessageBox.Show("You Do Not Have Permission");
    return;
    }
 
Share this answer
 
Comments
Member 11280947 1-Feb-16 5:42am    
Thank You
The problem here is you are using the wrong Control for this task.

1. if you want to show a text notice to the user, that they can't interact with: use a Label.

2. use a TextBox when having the user edit the contents means something.

3. perform validation as soon as possible and keep Controls that you do not want the user to interact with disabled until using those Controls is "legal." Why let the user make a stupid mistake in the first place ?

4. consider using a UI element like a StatusBar to keep the user informed about the current state of the UI as it effects their possible choices.
 
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