RadComboBox Validation

4 posts, 1 answers
  1. Mohamed Salah Al-Din
    Mohamed Salah Al-Din avatar
    29 posts
    Member since:
    Aug 2009

    Posted 19 Sep 2010 Link to this post

    Hi,
    I am trying to validate rad combobox in alot of ways, even i used the simplest way but it's not working, even it was working correctly in 2009 Q3 version.

    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
            <asp:DropDownList ID="ddl" runat="server">
                <asp:ListItem Text="aaaa" Value="1"></asp:ListItem>
                <asp:ListItem Text="bbbb" Value="2"></asp:ListItem>
            </asp:DropDownList>
        <asp:RequiredFieldValidator ID="ddlrfv" runat="server" Display="Dynamic"
            ControlToValidate="ddl" ErrorMessage="Please Select"
            InitialValue ="-1" Text="*" ValidationGroup="ddl_vg">
        </asp:RequiredFieldValidator>
        <telerik:RadComboBox ID="rcb" runat="server" ValidationGroup="ddl_vg" Skin="Default" Width="200px" CausesValidation="true">
            <Items>
                <telerik:RadComboBoxItem Text="aaaa" Value="1" />
                <telerik:RadComboBoxItem Text="bbbb" Value="2" />
            </Items>
        </telerik:RadComboBox>
        <asp:RequiredFieldValidator ID="rcbrfv" runat="server" Display="Dynamic"
            ControlToValidate="rcb" ErrorMessage="Please Select"
            InitialValue ="-1" Text="*" ValidationGroup="ddl_vg">
        </asp:RequiredFieldValidator>
        <br />
        <br />
        <asp:Button ID="btn" runat="server" Text="Click" ValidationGroup="ddl_vg" OnClick="btn_Click" />
         
        </telerik:RadAjaxPanel>

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    this.rcb.Items.Insert(0, new RadComboBoxItem("select item", "-1"));
    this.ddl.Items.Insert(0, new ListItem("select", "-1"));
    }      
    }

    i think the above is the simplest example and it's not working, although i need to use it to validate rcb with autocomplete functionality or with filteration functionality.

    i am using version 2010 Q1
  2. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 20 Sep 2010 Link to this post

    The problem with your code is that the InitialValue setting on your RequiredFieldValidator should be "select item", since that is what it's validating against, the Text property, not the Value property.

    I hope that helps.
  3. Mohamed Salah Al-Din
    Mohamed Salah Al-Din avatar
    29 posts
    Member since:
    Aug 2009

    Posted 21 Sep 2010 Link to this post

    Dear Cori,
    Thanks for your reply, and for your solution i know that it will work if i validated it that way, but it's not the same way as the Normal ASP.Net works.
    that's why i am asking Telerik people , if i chose to use Telerik ComboBox instead of the normal DropDownBox i have to change all the validation to validate the text instead of the value.

    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
            <asp:DropDownList ID="ddl" runat="server">
                <asp:ListItem Text="aaaa" Value="1"></asp:ListItem>
                <asp:ListItem Text="bbbb" Value="2"></asp:ListItem>
            </asp:DropDownList>
        <asp:RequiredFieldValidator ID="ddlrfv" runat="server" Display="Dynamic"
            ControlToValidate="ddl" ErrorMessage="Please Select"
            InitialValue ="-1" Text="*" ValidationGroup="ddl_vg">
        </asp:RequiredFieldValidator>
        <telerik:RadComboBox ID="rcb" runat="server" ValidationGroup="ddl_vg" Skin="Default" Width="200px" CausesValidation="true">
            <Items>
                <telerik:RadComboBoxItem Text="aaaa" Value="1" />
                <telerik:RadComboBoxItem Text="bbbb" Value="2" />
            </Items>
        </telerik:RadComboBox>
        <asp:RequiredFieldValidator ID="rcbrfv" runat="server" Display="Dynamic"
            ControlToValidate="rcb" ErrorMessage="Please Select"
            InitialValue ="-1" Text="*" ValidationGroup="ddl_vg">
        </asp:RequiredFieldValidator>
        <br />
        <br />
        <asp:Button ID="btn" runat="server" Text="Click" ValidationGroup="ddl_vg" OnClick="btn_Click" />
         
        </telerik:RadAjaxPanel>

    protected void Page_Load(object sender, EventArgs e)
        {
    if (!IsPostBack)
            {
                this.rcb.Items.Insert(0, new RadComboBoxItem("select", "-1"));
                this.ddl.Items.Insert(0, new ListItem("select", "-1"));
            }
             
        }


  4. Answer
    Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 22 Sep 2010 Link to this post

    Hello Mohamed Salah Al-Din,

    By design RadComboBox can be easily validated against the Text of its items.

    Please find more details about this topic at "Validate Combobox by Value"  help article.
    At the same article you can find an example how to validate RadComboBox by value.

    Best wishes,
    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
Back to Top