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

Required Field validator with combobox

1 Answer 439 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 28 Mar 2011, 06:31 AM
Hello,

I've implemented a requiredfieldvalidator for a radcombobox which works fine on submitting the form, however I would like to show the red asterisk before the page is submitted to indicate to the user that the field is required.  Using

Page.Validate();

in the Page_load event on the server activates the required field validators that are defined against text boxes, but I can't get the validator associated  with the combobox to show.

 
      <table>
        <tr>
            <td><telerik:RadComboBox id="ddlCostCategory" DataTextField="Name" DataValueField="ID" runat="server" SkinID="WideDll"  ></telerik:RadComboBox></td>
            <td><asp:RequiredFieldValidator runat="server" ControlToValidate ="ddlCostCategory" ID="reqValCostCategory" Text="*" ErrorMessage="Cost Category is required" InitialValue="[Select...]" ></asp:RequiredFieldValidator></td>
        </tr>
      </table>

The combobox si bound to a list with the first item having the text of [Select...] before the Page.Validate is called:

var query2 = from c in PNGC_SmartGridContext.CostCategories select c;
               IList<CostCategory> _costCategories = query2.ToList<CostCategory>();
               _costCategories.Insert(0, new CostCategory() { ID = 0, Name = "[Select...]" });
               ddlCostCategory.DataSource = _costCategories;
               ddlCostCategory.DataBind();

Note that the actual validation on submit works fine, it's just the ability to pre-trigger the red asterisk that would be great.

Thanks

Jonathan

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 31 Mar 2011, 06:45 AM
Hello Jonathan,

Instead of creating an item with Text="Select...", you can set EmptyMessage="Select..." and use the workaround suggested in this forum thread -
http://www.telerik.com/community/forums/aspnet-ajax/combobox/emptymessage-allowcustomtext-and-radcombobox-validation-request.aspx

I hope this helps.

Greetings,
Peter
the Telerik team
Tags
ComboBox
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or