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

RadComboBox Validation

3 Answers 281 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Mohamed Salah Al-Din
Top achievements
Rank 1
Mohamed Salah Al-Din asked on 19 Sep 2010, 02:26 PM
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

3 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 20 Sep 2010, 06:16 PM
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.
0
Mohamed Salah Al-Din
Top achievements
Rank 1
answered on 21 Sep 2010, 06:13 AM
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"));
        }
         
    }


0
Accepted
Kalina
Telerik team
answered on 22 Sep 2010, 01:00 PM
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
Tags
ComboBox
Asked by
Mohamed Salah Al-Din
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Mohamed Salah Al-Din
Top achievements
Rank 1
Kalina
Telerik team
Share this question
or