Search Forum
(53671 Postings)
Search Site/Articles

Archived Articles
712 Articles

C# Books
C# Consultants
What Is C#?
Download Compiler
Code Archive
Archived Articles
Advertise
Contribute
C# Jobs
Beginners Tutorial
C# Contractors
C# Consulting
Links
C# Manual
Contact Us
Legal

GoDiagram for .NET from Northwoods Software www.nwoods.com


 
Printable Version

TextBox Validation
By Prasad H.

Sometimes we can make the Textbox to Accept Only Number is any other value is entered then we may alert the user to enter the Numeric value.In C# what we have to do is write the Validate event for each and every Textbox to be validated for Numbers.

What the program does is it extends the C#'s Textbox class and Wrap the Validated within the child class so that user can the ChildClass for textbox to be validated for numbers without writing code for each and every textbox.

ie.

Consider for eg we want to validate for 2 Textbox then we have to write code like this:

TextBox t1=new TextBox();
TextBox t2=new TextBox();

t1+=new CancelEventHandler(Validatingfunction)
t2+=new CancelEventHandler(Validatingfunction)

using the Code i sent to you without worrying abt the
Validation u can simply code it like this:

NumberBox n1=new NumberBox();
NumberBox n2=new NumberBox();

The above 2 will create 2 textbox and has all the features of textbox along with the Number validation in built.

Download NumberBox.cs