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

RadComboBox Validation with EmptyMessage set...

2 Answers 201 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
gary
Top achievements
Rank 1
gary asked on 16 Aug 2010, 10:42 PM
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 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Aug 2010, 08:46 AM
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.
0
gary
Top achievements
Rank 1
answered on 17 Aug 2010, 02:36 PM
Hello Princy,

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

Thanks Again,
Gary
Tags
ComboBox
Asked by
gary
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
gary
Top achievements
Rank 1
Share this question
or