.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Control Validation using C#.net

Posted By:Narayanan       Posted Date: June 26, 2012    Points: 40    Category: Windows Form Controls    URL: http://www.dotnetspark.com  

Here , I gave a step by step Processing of Validation of Controls in Windows Application.
 

Step by step to Control Validation:
  • Add a Form
  • Go to Form Property window.
  • Disable AutoValidate .

  • Add a Text Box in the Form.
  • Add a Button in the Form.
  • Verify CausesValidation is true.

The following code add into Validating Event of TextBox and Click event of Button.

if (textBox1.Text.Length == 0)
            {
                e.Cancel = true;
            }
            else
            {
                e.Cancel = false;
            }

     TextBox Validating Event:
  if (this.ValidateChildren())
            {
                MessageBox.Show("Validation succeeded!");
            }
            else
            {
                MessageBox.Show("Validation failed.");
            }


  

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend