requiredfieldvalidator not working...

14 posts, 0 answers
  1. Saqib
    Saqib avatar
    24 posts
    Member since:
    Jan 2014

    Posted 06 Apr 2014 Link to this post

    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>
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 Apr 2014 in reply to Saqib Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Saqib
    Saqib avatar
    24 posts
    Member since:
    Jan 2014

    Posted 07 Apr 2014 in reply to Princy Link to this post

    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?
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 Apr 2014 in reply to Saqib Link to this post

    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.
  6. Saqib
    Saqib avatar
    24 posts
    Member since:
    Jan 2014

    Posted 09 Apr 2014 in reply to Princy Link to this post

    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>
  7. Saqib
    Saqib avatar
    24 posts
    Member since:
    Jan 2014

    Posted 09 Apr 2014 in reply to Saqib Link to this post

    Correction:

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


    Wish there is a way to edit the post!
  8. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 10 Apr 2014 in reply to Saqib Link to this post

    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.
  9. Aneliya Petkova
    Admin
    Aneliya Petkova avatar
    207 posts

    Posted 10 Apr 2014 Link to this post

    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.

     
  10. Saqib
    Saqib avatar
    24 posts
    Member since:
    Jan 2014

    Posted 10 Apr 2014 in reply to Aneliya Petkova Link to this post

    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?

  11. Aneliya Petkova
    Admin
    Aneliya Petkova avatar
    207 posts

    Posted 14 Apr 2014 Link to this post

    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.

     
  12. Saqib
    Saqib avatar
    24 posts
    Member since:
    Jan 2014

    Posted 14 Apr 2014 in reply to Aneliya Petkova Link to this post

    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.
  13. Aneliya Petkova
    Admin
    Aneliya Petkova avatar
    207 posts

    Posted 16 Apr 2014 Link to this post

    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.

     
  14. Saqib
    Saqib avatar
    24 posts
    Member since:
    Jan 2014

    Posted 16 Apr 2014 in reply to Aneliya Petkova Link to this post

    How can we stop the event handle to fire if nothing is selected in combo box using requiredfieldvalidator?
  15. Aneliya Petkova
    Admin
    Aneliya Petkova avatar
    207 posts

    Posted 17 Apr 2014 Link to this post

    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.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017