RadComboBox Validation with EmptyMessage set...

3 posts, 0 answers
  1. gary
    gary avatar
    14 posts
    Member since:
    Aug 2010

    Posted 16 Aug 2010 Link to this post

    Hi,

    I have a RadComboBox that has its EmptyMessage property set to - Select Table -. I am trying to create a some validation where if the user does not select a Table from the RadComboBox an error message is displayed saying "Please select a table..."

    //RadComboBox:

     

    <telerik:RadComboBox ID="RadComboBoxTables" Runat="server"

     

     

    DataSourceID="ObjectDataSourceMetaDateTables" DataTextField="Name"

     

     

    DataValueField="Name" Label="Table: "

     

     

    ondatabound="Tables_DataBound"

     

     

    onitemsrequested="Tables_ItemsRequested"

     

     

    OnClientSelectedIndexChanging="metaDataTableSelected"

     

     

    LabelCssClass="riLabel" Width="100%"

     

     

    EmptyMessage="- Select table - "

     

     

    ValidationGroup="AttrValidationGroup">

     

     

    </telerik:RadComboBox>

    I tried doing  this 2 ways:

    1. I used a CompareValidator..This should display the error message if the user does not select a table; however, no error message is displayed. If select -Select table - from RadComboBox again, no error is displayed.  Is/Can the EmptyMessage be used here as the value to compare to?

    (NOTE: if I change the Operator to Operator=Equal, then it displays the error if user doesn't select anything, selects a table, or selects "- Select table - " from RadComboBox.)

    //CompareValidator:

     

     

    <asp:CompareValidator

     

     

     

     

     

    ID="CompareValidatorRadComboxBoxTables"

     

     

     

     

     

    runat="server"

     

     

     

     

     

    ValueToCompare=" - Select table - "

     

     

     

     

     

    Operator="NotEqual"

     

     

     

     

     

    ControlToValidate="RadComboBoxTables"

     

     

     

     

     

    ErrorMessage="Please select Table..."

     

     

    ValidationGroup="AttrValidationGroup">

     

     

     

     

     

    </asp:CompareValidator>

    I also tried using the Requiredfield Validator like a saw in an example on this site (http://demos.telerik.com/aspnet-ajax/combobox/examples/default/defaultcs.aspx  this example worked fine), but no error was displayed for my app.

    //RequiredFieldValidator:

     

     

    <asp:RequiredFieldValidator ID="RequiredFieldValidatorComboTxtBxTables"

     

     

     

     

     

    runat="server"

     

     

    ControlToValidate="RadComboBoxTables"

     

     

     

     

     

    ErrorMessage="Please select table from list..."

     

     

     

     

     

    ValidationGroup="AttrValidationGroup">

     

     

    </asp:RequiredFieldValidator>

     


    Any advice and/or help will be appreciated.

    Thanks in advance...
    gary

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 17 Aug 2010 Link to this post

    Hello Gary,

    I think the problem is because of not setting AllowCustomText property of RadComboBox.

    ASPX:
    <telerik:RadComboBox ID="RadComboBoxTables" runat="server" DataSourceID="ObjectDataSourceMetaDateTables" DataTextField="Name"  DataValueField="Name" EmptyMessage=" - Select table - " Label="Table: " LabelCssClass="riLabel" ValidationGroup="AttrValidationGroup" AllowCustomText="true">
    </telerik:RadComboBox>
     
    <asp:RequiredFieldValidator ID="RequiredFieldValidatorComboTxtBxTables" runat="server" ControlToValidate="RadComboBoxTables" ErrorMessage="Please select table from list..." ValidationGroup="AttrValidationGroup">
    </asp:RequiredFieldValidator>

    Also check whether you have set ValidationGroup when submitting the form like below.

    ASPX:
    <asp:Button ID="Button1" runat="server" Text="Validate" ValidationGroup="AttrValidationGroup" />

    Thanks,
    Princy.
  3. gary
    gary avatar
    14 posts
    Member since:
    Aug 2010

    Posted 17 Aug 2010 Link to this post

    Hello Princy,

    Thanks for your suggestion. Adding AllowCustomText="true" did the job.

    Thanks Again,
    Gary
Back to Top