Click here to Skip to main content
16,011,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want's to make a function/subroutine which check for required field and allow control to enter only number or alphabet in asp.net web application.

Using function i Want to pass all controls of .aspx page one by one to function on submit button which is used for multiple form.

If u have any suggestion about validation controls of asp.net/ ajax/ aspx control which solve above problem ,
please tell me.
Posted

Use custom validators and have them all call a function that's in a common JS file.
 
Share this answer
 
The CustomValidator control provides user-defined validation function for an input control. There are two types of validation
1. Server side
2. Client side
Here is the solution for your problem
Insert a custom validator control in the web page and assign the following properties
<asp:CustomValidator runat=server
controltovalidate="txtName"
errormessage="ID is not valid"
OnServerValidate="CheckID" />

Write the following code in code-behind of the web page for validation
public void CheckID(Object source, ServerValidateEventArgs args)
{
args.IsValid = true;
foreach (char chr in args.Value.ToString())
{
if (char.IsDigit(chr) == false && char.IsLetter(chr) == false)
{
args.IsValid = false;
return;
}
}
}

regards
Kumaran
 
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