This is a migrated thread and some comments may be shown as answers.

Load On Demand and Required Field Validator

9 Answers 195 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Anderson
Top achievements
Rank 1
Anderson asked on 22 May 2008, 04:04 PM
We are using a RadComboBox with the load on demand feature as demoed here:
http://www.telerik.com/demos/aspnet/prometheus/ComboBox/Examples/PopulatingWithData/AutoCompleteSql/DefaultCS.aspx

We have a required field validator associated with this ComboBox.  In the case that a user types in some gibberish and hits "submit", since a valid option was not selected, we would expect the required field validator to fire on the client-side and stop the postback, but this is not the case.

Is there something I'm missing here?

9 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 26 May 2008, 08:35 AM
Hello Anderson,

The RequredFieldValidator checks if there is a text in the input area of the combobox. In your case this is true and the page is considered valid.

I suggest that you use a CustomFieldValidator. Here is how you can accomplish the task:

<asp:CustomValidator ID="CustomValidator1"  
    runat="server"  
    ControlToValidate="RadComboBox1" 
    ValidateEmptyText="True" 
    ClientValidationFunction="validateCombo" 
    ErrorMessage="You have to select an item from the list"
</asp:CustomValidator> 

<script type="text/javascript"
function validateCombo(source, args) 
   args.IsValid = false
   var combo = $find("<%= RadComboBox1.ClientID %>"); 
   var text = combo.get_text(); 
   var item = combo.findItemByText(text); 
   if (item) 
   { 
       args.IsValid = true
   } 
</script> 

I hope this helps.

Greetings,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
n
Top achievements
Rank 1
answered on 16 Jan 2009, 04:21 PM
Hi there,

I need to obtain a reference to the combobox using the parameter source, wich is the customvalidator. I can obtain the combobox ID via  source.coontroltovalidate.
But , then, i can't obtain the reference to the combo element rigth, since when it tries to get the Text (combo.GetText) , it's says the object does not contains that method.

Can I please get some help on how i can get this working.

thanks,Nuno.
0
Veselin Vasilev
Telerik team
answered on 19 Jan 2009, 12:42 PM
Hello Nuno,

GetText() is a method of the "classic" RadComboBox. Do you use that version?
If you are using RadControls for ASP.NET AJAX you need to use get_text() as shown in my previous post.


All the best,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
n
Top achievements
Rank 1
answered on 19 Jan 2009, 01:01 PM
Hello,

Yes, I am using that version.


0
Veselin Vasilev
Telerik team
answered on 20 Jan 2009, 01:49 PM
Hi Nuno,

Maybe you are not obtaining a proper reference to the RadComboBox.

Can you please paste here some relevant code so we can observe it.


Greetings,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
n
Top achievements
Rank 1
answered on 20 Jan 2009, 06:49 PM
Im associating a custom Control to the RadComboBox, and then on the Client Side i doing something like this

 
function validateCombo(source, args) {  
  args.IsValid = false;  
  var combo = document.getElementById(source.controltovalidate); //I want a reference to the radcombobox on the client side
 
 
  var text = combo.GetText();  
 }  


Thanks,Nuno.
0
Veselin Vasilev
Telerik team
answered on 23 Jan 2009, 03:43 PM
Hello,

You need to get a reference to the combobox in the following way:

var combo = <%= source.controltovalidate %>; 


Best wishes,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
n
Top achievements
Rank 1
answered on 02 Feb 2009, 09:45 AM
Hi there,

I cant use those server side tags...
I need to get the reference do the radcombobox on the client side.

Thanks.

Nuno.
0
Veselin Vasilev
Telerik team
answered on 03 Feb 2009, 03:14 PM
Hello Nuno,

Please check this article:
Getting the Client-Side Instance of Telerik RadComboBox

Greetings,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
ComboBox
Asked by
Anderson
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
n
Top achievements
Rank 1
Share this question
or