Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: (untagged)
eg...
i have a dropdownlist as client1 client2 client3........client10
and one textbox
&&
for each selected dropdownitem textbox should perform different validations is it possible......
Posted
Comments
AmitGajjar 13-Sep-12 7:10am    
is this windows/web application ?
darshith 13-Sep-12 7:26am    
web application......
Kenneth Haugland 13-Sep-12 7:14am    
I have deleted your repost, dont do it again, use the Improve question if you have additional requirements.

Yes you can. Try something like this if I am getting you right:
C#
if(dropDownList1.SelectedIndex == 1)
{
  //call function say characterValidation();
}
else if(dropDownList1.SelectedIndex == 2)
   {
      //call function say numericValidation();
   }

and so on.
 
Share this answer
 
Comments
darshith 13-Sep-12 7:09am    
superb but for ten clients its not worth of writin these many lines....
is the other way there to solve this
Prasad_Kulkarni 13-Sep-12 7:11am    
Glad it works.
Do you really have 10 text box with respective 10 validations??

If so, use switch.
darshith 13-Sep-12 7:15am    
no i have only one textbox(textbox1)..... but there are 10 different clients in dropdownlist each client should have a different validations in (textbox1)
please help...........
Prasad_Kulkarni 13-Sep-12 7:18am    
Like what kind of validations, please elaborate.
darshith 13-Sep-12 7:42am    
waiting for ur reply....
Hi,

ofcourse it is possible. You can use Custom Validator. this will accept the javascript function as validation function and based on the validation you have to set IsValid to True or False.

try like this,

JavaScript
function fnValidate(sender,args)
{
  var ddl = document.getElementById("dropdownList1");
  
 if(ddl.options.value == "client1")
 {
   var txt = document.getElementById("Textbox1");
   //validate text box
   
   args.IsValid=true; //based on the validation set the true or false.
 }
 elseif(ddl.options.value == "client2")
 {
   var txt = document.getElementById("Textbox1");
   //validate text box
   
   args.IsValid=true; //based on the validation set the true or false.
 }
return;
}


check this[^] for more on Custom validators. Set the ClientValidationFunction to above javascript function.

hope it helps.
 
Share this answer
 
Comments
darshith 13-Sep-12 9:00am    
for client1 textbox should accept only integers
and for client2 only alphabets please help

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