This is a migrated thread and some comments may be shown as answers.
Load-On-Demand RadComboBox does not raise CustomValidator.ServerValidate when blank
2 Answers 82 Views
This is a migrated thread and some comments may be shown as answers.
Wyatt
Top achievements
Rank 1
Wyatt asked on 28 May 2010, 02:59 AM
Following this documentation, I am requiring that a value be set in a Load-On-Demand RadComboBox.  Both the client and server validation events are raised when text has been entered.  If there is no text, neither the client nor the server validation events are raised.  Also of note, MarkFirstMatch = True, ShowMoreResultsBox = True, and EnableVirtualScrolling = True.

I was able to fix this problem by adding a RequiredFieldValidator in addition to the CustomValidation.  Is this by design?

2 Answers, 1 is accepted

Sort by
0
Kalina
Telerik team
answered on 02 Jun 2010, 02:52 PM
Hello Wyatt,

You can use the CustomValidator control to validate the RadComboBox upon value and at the same time - to validate if the RadComboBox input is empty. 

Here is one basic sample to illustrate the approach:
<telerik:RadComboBox ID="RadComboBox1"  AllowCustomText="true"
    EnableLoadOnDemand="true" 
    OnItemsRequested="RadComboBox1_OnItemsRequested"
    MarkFirstMatch="true"
    ShowMoreResultsBox="true"
    EnableVirtualScrolling="true"
    runat="server">
    
</telerik:RadComboBox>
<asp:Button ID="btnTSubmit" runat="server"
    CausesValidation="true" Text="Submit" />
<asp:CustomValidator ID="CustomValidator1" runat="server"
    ClientValidationFunction="validateCombo"
    ErrorMessage="You must select an item with even value"
    OnServerValidate="CustomValidator1_ServerValidate">
</asp:CustomValidator>
 
<script type="text/javascript">
    function validateCombo(source, args) {
        debugger
        args.IsValid = false;
        var combo = $find("<%= RadComboBox1.ClientID %>");
 
        var text = combo.get_text();
        if (text.length < 1) {
            args.IsValid = false;
        }
        else {
            var node = combo.findItemByText(text);
            if (node) {
                var value = node.get_value();
                if (value.length > 0 && value % 2 == 0) {
                    args.IsValid = true;
                }
            }
            else {
                args.IsValid = false;
            }
        }
    }
</script>

protected void RadComboBox1_OnItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
    
    this.RadComboBox1.Items.Add( new RadComboBoxItem("-- Select item --"));
    this.RadComboBox1.Items.Add(new RadComboBoxItem("Item with No Value"));
    this.RadComboBox1.Items.Add(new RadComboBoxItem("Item with Value=1", "1"));
    this.RadComboBox1.Items.Add(new RadComboBoxItem("Item with Value=2", "2"));
    this.RadComboBox1.Items.Add(new RadComboBoxItem("Item with Value=3", "3"));
    this.RadComboBox1.Items.Add(new RadComboBoxItem("Item with Value=4", "4"));
 
         
}

Please note that if you use the RadComboBox control to raise the PostBack event (by setting the AutoPostBack to "true") -  naturally there will be no PostBack raised and the CustomValidator will not fire.

All the best,
Kalina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Eric Villemure
Top achievements
Rank 1
answered on 24 Aug 2010, 02:06 PM
Hi, I think I've had the same problem as yours.

I've found the solution here http://www.telerik.com/community/forums/aspnet-ajax/combobox/bug-custom-validation-in-particular-situation.aspx

Let me know if it helps
Asked by
Wyatt
Top achievements
Rank 1
Answers by
Kalina
Telerik team
Eric Villemure
Top achievements
Rank 1
Share this question
or