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

Required Filed Validator for RadCombobox with templates is not working

4 Answers 27 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Balageetha
Top achievements
Rank 1
Balageetha asked on 07 Aug 2014, 07:15 AM
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.









    

4 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 12 Aug 2014, 06:35 AM
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.

 
0
Balageetha
Top achievements
Rank 1
answered on 12 Aug 2014, 06:52 AM
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...
0
Accepted
Shinu
Top achievements
Rank 1
answered on 12 Aug 2014, 08:35 AM
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.
0
Balageetha
Top achievements
Rank 1
answered on 12 Aug 2014, 09:02 AM
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.
Tags
DropDownList
Asked by
Balageetha
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Balageetha
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Share this question
or