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

requiredfieldvalidator not working...

13 Answers 1126 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Saqib
Top achievements
Rank 1
Saqib asked on 07 Apr 2014, 03:47 AM
I have a combox box that I need to be required field.
I have 2 BUTTONS on page.
The first button "test" able to validate but second button doesnt!!Any help! Thanks,

<td valign="top">
<telerik:RadComboBox ID="cbSite" runat="server" EmptyMessage="Select" Height="200"
Width="200">
</telerik:RadComboBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="cbSite" 
runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<asp:Button ID="test" runat="server" Text="test" />
</td>
<td style="text-align: left">
</td>
<td valign="bottom">
<asp:Button ID="btnSubmit" runat="server" Text="Submit"  /><-- THIS DOESNT VALIDATE
</td>

13 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 07 Apr 2014, 09:02 AM
Hi Saqib,

The provided code is working fine at my end. One suggestion is that please try to set the ValidationGroup for all the control as follows. The ValidationGroup property specifies which group of control is validated on validation.

ASPX:
<table>
    <tr>
        <td valign="top">
            <telerik:RadComboBox ID="cbSite" runat="server" EmptyMessage="Select" Height="200" Width="200" ValidationGroup="cbSiteValidate">
                <Items>
                    <telerik:RadComboBoxItem Text="Item1" />
                    <telerik:RadComboBoxItem Text="Item2" />
                </Items>
            </telerik:RadComboBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="cbSite" runat="server" ErrorMessage="RequiredFieldValidator" ValidationGroup="cbSiteValidate">
            </asp:RequiredFieldValidator>
            <asp:Button ID="test" runat="server" Text="test" ValidationGroup="cbSiteValidate" />
        </td>
        <td style="text-align: left">
        </td>
        <td valign="bottom">
            <asp:Button ID="btnSubmit" runat="server" Text="Submit" ValidationGroup="cbSiteValidate" />
        </td>
    </tr>
</table>

Let me know if you have any concern.
Thanks,
Princy.
0
Saqib
Top achievements
Rank 1
answered on 07 Apr 2014, 03:43 PM
I tried with all possible ways by making validationgroup and without but no way its working.
My combo box is different than yours. Its dynamic from database with Header/Item templates if that's the reason its not working?
0
Princy
Top achievements
Rank 2
answered on 08 Apr 2014, 03:13 AM
Hi Saqib,

Please have a look into the sample code snippet which works fine at my end.

ASPX:
<table>
    <tr>
        <td valign="top">
            <telerik:RadComboBox runat="server" ID="cbSite" Height="190px" Width="420px" EmptyMessage="select" DataSourceID="SqlDataSource1" OnItemDataBound="RadComboBox1_ItemDataBound" HighlightTemplatedItems="true" ValidationGroup="cbSiteValidate">
                <HeaderTemplate>
                    <ul>
                        <li class="col1">Contact Name</li>
                    </ul>
                </HeaderTemplate>
                <ItemTemplate>
                    <ul>
                        <li class="col1">
                            <%# DataBinder.Eval(Container.DataItem, "ContactName") %></li>
                    </ul>
                </ItemTemplate>
            </telerik:RadComboBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="cbSite" runat="server" ErrorMessage="RequiredFieldValidator" ValidationGroup="cbSiteValidate">
            </asp:RequiredFieldValidator>
            <asp:Button ID="test" runat="server" Text="test" ValidationGroup="cbSiteValidate" />
        </td>
        <td style="text-align: left">
        </td>
        <td valign="bottom">
            <asp:Button ID="btnSubmit" runat="server" Text="Submit" ValidationGroup="cbSiteValidate" />
        </td>
    </tr>
</table>

C#:
protected void RadComboBox1_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
{
    //set the Text and Value property of every item
    e.Item.Text = ((DataRowView)e.Item.DataItem)["ContactName"].ToString();
    e.Item.Value = ((DataRowView)e.Item.DataItem)["CustomerID"].ToString();
}

Please provide your code if it doesn't help.
Thanks,
Princy.
0
Saqib
Top achievements
Rank 1
answered on 09 Apr 2014, 09:12 PM
This is my code:

<
table  style="border:1px solid black;" >
    <tr>
        <td valign="top">
            <telerik:RadComboBox ID="cbLoc" runat="server" EmptyMessage="Select " Height="200" Width="200"
                DropDownWidth="270" ValidationGroup="cbValidate"
                InputType="Text" AllowCustomEntry="false" EnableClientFiltering="true" Filter="Contains" Label=" Names: "
                DataSourceID="ddlName" DataTextField="LocName" DataValueField="LocKey"
                HighlightTemplatedItems="true"
                Skin="Office2010Silver">
                <HeaderTemplate>
                    <table style="width: 240px" cellspacing="0" cellpadding="0">
                        <tr>
                            <td style="width: 40px;">ID
                            </td>
                            <td style="width: 200px; text-align: left">Name
                            </td>
                        </tr>
 
                    </table>
 
                </HeaderTemplate>
                <ItemTemplate>
                    <table style="width: 240px" cellpadding="0" cellspacing="0">
                        <tr>
                            <td style="width: 40px;">
                                <%# DataBinder.Eval(Container.DataItem, "ID")%>
                            </td>
                            <td style="width: 200px; text-align: left">
                                <%# DataBinder.Eval(Container.DataItem, "Name")%>
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
            </telerik:RadComboBox>
 
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="cbSite" ValidationGroup="cbValidate"
                runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
            <asp:Button ID="test" runat="server" Text="test" ValidationGroup="cbValidate" />
        </td>
 
         
        <td valign="bottom">
            <asp:Button ID="btnSubmit" runat="server" Text="Submit" ValidationGroup="cbValidate"/>
        </td>
    </tr>
</table>
0
Saqib
Top achievements
Rank 1
answered on 09 Apr 2014, 09:14 PM
Correction:

asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="cbLoc" ValidationGroup="cbValidate"                runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>


Wish there is a way to edit the post!
0
Princy
Top achievements
Rank 2
answered on 10 Apr 2014, 05:02 AM
Hi Saqib,

I tried your code and it is working fine at my end. Unfortunately I couldn't replicate the issue at my end.

Thanks,
Princy.
0
Aneliya Petkova
Telerik team
answered on 10 Apr 2014, 08:24 AM
Hello Saqib,

I have inspected the provided code snippet and I am not able to reproduce the issue you are facing. Please find attached the project I used for testing at my end. Please try it and let me know how it works at your side.

I will be waiting for your reply.

Regards,
Aneliya Petkova
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Saqib
Top achievements
Rank 1
answered on 10 Apr 2014, 10:35 PM
I now know the reason of above behavior that one of the button didn't have event handled in code behind and the other button did.
The one where the event handled was making database call using DAL and with empty parameter.

Anyways, how to fix this issue? With this behavior, how Requiredfieldvalidator would be helpful?

0
Aneliya Petkova
Telerik team
answered on 14 Apr 2014, 11:02 AM
Hello Saqib,

We have tested different scenarios, but we were not able to reproduce the issue. Based on the supplied information, it is hard to determine what is causing the issue you are experiencing. It would be very helpful if you modify the project I attached in my previous post and send it to us. We will test it locally and advise you further.

Regards,
Aneliya Petkova
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Saqib
Top achievements
Rank 1
answered on 14 Apr 2014, 03:40 PM
When button is clicked, the button event handler is fired.
I m sure it is firing for you too.
So inside my handler, I m running query which is expecting a selected field from combobox which gets executed and errors out.

Let me know if you can produce above steps.
0
Aneliya Petkova
Telerik team
answered on 16 Apr 2014, 10:30 AM
Hello Saqib,

Unfortunately without being able to test and debug your implementation of the event handler of the button, it is indeed very hard to determine what might be causing the issue you are facing. And yes, the event handler of the button is fired at our side too, but we need your custom code in the event handler.
I advise you to open a support ticket, because this will allow you to attach a project we can run and test.

Regards,
Aneliya Petkova
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Saqib
Top achievements
Rank 1
answered on 16 Apr 2014, 09:39 PM
How can we stop the event handle to fire if nothing is selected in combo box using requiredfieldvalidator?
0
Aneliya Petkova
Telerik team
answered on 17 Apr 2014, 01:24 PM
Hello Saqib,

As far as I understand, you want to implement some custom validation of the RadComboBox. In this case you could use CustomValidation control. Please check the following help articles on how to validate the combobox using custom validation:

http://www.telerik.com/help/aspnet-ajax/combobox-validate-combobox-value.html
http://www.telerik.com/help/aspnet-ajax/combobox-behavior-validation.html

Hope this would be helpful.

Regards,
Aneliya Petkova
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
ComboBox
Asked by
Saqib
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Saqib
Top achievements
Rank 1
Aneliya Petkova
Telerik team
Share this question
or