Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I am making window based application .I am having one label customer name in a form.I want to use validatin whenever user do not enter name.how can I do this
Posted

On form submit event, check if the name textbox is empty or have some data in it. If not, raise a message that it is needed. Stop the execution. Did you try?
 
Share this answer
 
Comments
shivani 2013 7-May-11 4:06am    
can u explain it more using code
Sandeep Mewara 7-May-11 4:08am    
There is nothing much to explain/code for it. If you even try once, you can write it too.
It depends on how much validation you need to do and when you need to do it.
You can validate when the user presses a button - to enter the information for example.
Or, you can validate when the user moves away from the TextBox.

To do the former, just do your checks in the Button.Click event.
To do the later, handle the TextBox.Leave event.

Personally, I would go for the Button.Click route: It allows the user to fill things in, in whatever order he chooses.


"can u explain it more using code"
private void myEnterButton_Click(object sender, EventArgs e)
    {
    if (!string.IsNullOrEmpty(myTextBox.Text) && myTextBox.Text != "Bad customer")
        {
        ... All ok.
        }
    else
        {
        ... bad Validation
        }
    }
 
Share this answer
 
v2
Comments
shivani 2013 7-May-11 4:06am    
can u explain it more using code
OriginalGriff 7-May-11 4:24am    
Answer updated

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