Required Filed Validator for RadCombobox with templates is not working

5 posts, 1 answers
  1. Balageetha
    Balageetha avatar
    12 posts
    Member since:
    May 2014

    Posted 07 Aug 2014 Link to this post

    Hi,

        I am using a user control with the RadComobox with Header and Item Templates as follows,

    .aspx,


                   <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="EmployeesList.ascx.cs" Inherits="Sampige.Web.iprocessWebPortal.SiteAdmin.UserControls.EmployeesList" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="rad" %>

    <div style="width: 250px">
        <table>
            <tr>
                <td>
                  <%-- <rad:RadComboBox ID="cmbEmployee" runat="Server" Width="150px" DataTextField="EmployeeName" DropDownWidth="200px"
                                DataValueField="EmployeeID" AutoPostBack="true" >
                   </rad:RadComboBox>--%>
                   <rad:RadComboBox ID="cmbemployeeselector" runat="server" Width="160px" HighlightTemplatedItems="true" ForeColor="Black" Filter="StartsWith"
                     DataTextField="EmployeeName" DropDownWidth="450px"
                    DataValueField="EmployeeID" CausesValidation="false">
                    
                    <HeaderTemplate>
                        <table style="width: 100%;" cellspacing="0" cellpadding="0">
                            <tr>
                                <td style="width: 33%; ">
                                  Employee Name
                                </td>
                                <td style="width: 33%;">
                                   Area Name
                                </td>
                                <td style="width: 30%;">
                                  Group Name
                                </td>
                            </tr>
                        </table>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <table style="width: 100%;" cellspacing="1" cellpadding="1">
                            <tr>
                                <td style="width: 33%;">
                                    <%# DataBinder.Eval(Container, "Attributes['EmployeeName']")%>
                                </td>
                                <td style="width: 33%;">
                                    <%# DataBinder.Eval(Container, "Attributes['AreaName']")%>
                                </td>
                                <td style="width: 30%;">
                                    <%# DataBinder.Eval(Container, "Attributes['GroupName']")%>
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>
                </rad:RadComboBox>
                </td>
               
               
            </tr>
        </table>
    </div>

    .aspx.cs,
    ========

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using Telerik.Web.UI;
    using Sampige.BLL.Inspector;

    namespace Sampige.Web.iprocessWebPortal.SiteAdmin.UserControls
    {
        [ValidationProperty("EmployeeID")]
        public partial class EmployeesList : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {

            }

            protected void Page_Init(object sender, EventArgs e)
            {

                GetEmployees();
            }


            public string EmployeeID
            {

                get
                {
                    return cmbemployeeselector.SelectedItem.Value;
                   
                }
                set
                {
                    ViewState["EmployeeID"] = value;
                    SetComboItem(value, null);
                }
            }

            private void SetComboItem(string Value, string Text)
            {
                if (Value != null && Value != string.Empty)
                {
                    
                    cmbemployeeselector.SelectedItem.Value = Value;
                }
                else
                    GetEmployees();
            }

             public void GetEmployees()
            {
                DataTable dt = InspectorReport.LoadEmployeesList();
                cmbemployeeselector.Enabled = true;
                cmbemployeeselector.Items.Clear();
                RadComboBoxItem itemAll = new RadComboBoxItem();
                itemAll.Text = "--Select--";
                itemAll.Value = "-1";
                itemAll.Attributes.Add("EmployeeName", "--Select--");
                itemAll.Attributes.Add("AreaName", "--Select--");
                itemAll.Attributes.Add("GroupName", "--Select--");
                cmbemployeeselector.Items.Add(itemAll);
                cmbemployeeselector.SelectedValue = "-1";
                itemAll.DataBind();
                
                foreach (DataRow dataRow in dt.Rows)
                {
                    RadComboBoxItem item = new RadComboBoxItem();

                    item.Text = (string)dataRow["EmployeeName"];
                    item.Value = dataRow["EmployeeID"].ToString();

                    string ItemCode = dataRow["EmployeeName"].ToString();
                    string ItemType = dataRow["AreaName"].ToString();
                    string AreaName = dataRow["GroupName"].ToString();

                    item.Attributes.Add("EmployeeName", ItemCode);
                    item.Attributes.Add("AreaName", ItemType);
                    item.Attributes.Add("GroupName", AreaName);

                    cmbemployeeselector.Items.Add(item);
                    item.DataBind();
                }

                //cmbemployeeselector.SelectedValue = "-1";
            }

        }
        
    }





    When i use this user control in some another page i'm not getting the Required Filed Message in a Message box,

      <employeecombo:EmployeesList ID="Enteredby" runat="server" />
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator98" Display="Dynamic" runat="server"
                        ValidationGroup="Inspection" ErrorMessage="Entered by is Required" ControlToValidate="Enteredby"
                        InitialValue="-1"></asp:RequiredFieldValidator>


    In this aspx page I am using that user control and i am not getting the Required Field Validation Message in a Message Box..
    But it is showing a message(summary message) after i click on a save button.....
    But no where i am able to get the Message box..,


    Pls Help me...
    Thanks in Advance.









        
  2. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 12 Aug 2014 Link to this post

    Hello Balageetha,

    Could you be more specific and elaborate a bit more on which is the problematic scenario that you had encountered, regarding the usage of the RequiredFieldValidator and the RadComboBox. I have performed some local tests, base on the provided code snippet and its seems that the validator is correctly triggered.

    Regards,
    Nencho
    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Balageetha
    Balageetha avatar
    12 posts
    Member since:
    May 2014

    Posted 12 Aug 2014 in reply to Nencho Link to this post

    When i use that user control combobox in some other aspx pages, the combo box is not validating that is it is not showing the Required Field Validator message...
  5. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 12 Aug 2014 in reply to Balageetha Link to this post

    Hi Balageetha,

    I guess you want to use RequiredFieldValidator for UserControl. Please remove the InitialValue property from the RequiredFieldValidator and add the below C# code snippet in the UserControl Page.

    ASPX:
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" Display="Dynamic" runat="server" ValidationGroup="Inspection" ErrorMessage="Entered by is Required" ControlToValidate="Enteredby"></asp:RequiredFieldValidator>

    UserControl C#:
    [ValidationProperty("Text")]
    public partial class RadDropDownList_ComboBox : System.Web.UI.UserControl
    {
            public string Text
            {
                get { return cmbEmployee.SelectedValue; }
            }
    }

    Thanks,
    Shinu.
  6. Balageetha
    Balageetha avatar
    12 posts
    Member since:
    May 2014

    Posted 12 Aug 2014 in reply to Shinu Link to this post

    Hi Shinu,

                     Thanks a lot for your reply.

                     I have placed the Required Field Validator in the User Control and had set the Initial Value = "--Select--" and now it is working fine..


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