Required Field validator with combobox

2 posts, 0 answers
  1. Jonathan
    Jonathan avatar
    132 posts
    Member since:
    Sep 2007

    Posted 28 Mar 2011 Link to this post

    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
  2. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 31 Mar 2011 Link to this post

    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
Back to Top