I am trying to add a required field validation to a RadComboBox which is defined in a .ascx file. I am using this combo box in many pages. So I wont be able to give required field validation in .ascx page. I have referenced this page in a .aspx page and used a drop down to load with list of combo box items Which works fine. If I add this required field validator I get this error saying
"Unable to find control id 'radcmbEmployeeSearch' referenced by the 'ControlToValidate' property of 'eventAdminRequired'".
I tried replacing the controltovalidate with eventAdminDropDown. I get error for this too. Don't know where I am going wrong.
Any help is much appreciated.
Thanks
"Unable to find control id 'radcmbEmployeeSearch' referenced by the 'ControlToValidate' property of 'eventAdminRequired'".
I tried replacing the controltovalidate with eventAdminDropDown. I get error for this too. Don't know where I am going wrong.
Any help is much appreciated.
<telerik:RadComboBox ID=
"radcmbEmployeeSearch"
runat=
"server"
EmptyMessage=
"Select Event Admin"
AllowCustomText=
"true"
EnableLoadOnDemand=
"true"
ShowMoreResultsBox=
"true"
EnableVirtualScrolling=
"true"
OnItemsRequested=
"radcmbEmployeeSearch_ItemsRequested"
Height=
"200px"
>
</telerik:RadComboBox>
<td runat=
"server"
>
<EAdm:DropDown runat=
"server"
ID=
"eventAdminDropDown"
/>
<asp:requiredfieldvalidator id=
"eventAdminRequired"
runat=
"server"
display=
"Dynamic"
controltovalidate=
"radcmbEmployeeSearch"
initialvalue=
"0"
enableclientscript=
"True"
errormessage=
"Required"
>
</asp:requiredfieldvalidator>
</td>
8 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 23 Jan 2014, 09:27 AM
Hi,
Please try to make the RadComboBox with a public property in your UserControl Page as follows.
C#:
Then use the UniqueID of the RadComboBox to set the ControlToValidate in the Page_Load event of the ASPX page where you use the UserControlPage.
C#:
Hope this will helps you.
Thanks,
Princy.
Please try to make the RadComboBox with a public property in your UserControl Page as follows.
C#:
public
RadComboBox DropDownToValidate
{
get
{
return
radcmbEmployeeSearch;
}
}
Then use the UniqueID of the RadComboBox to set the ControlToValidate in the Page_Load event of the ASPX page where you use the UserControlPage.
C#:
protected
void
Page_Load(
object
sender, EventArgs e)
{
eventAdminRequired.ControlToValidate = WebUserControl31.DropDownToValidate.UniqueID;
}
Hope this will helps you.
Thanks,
Princy.
0
vvvv
Top achievements
Rank 1
answered on 23 Jan 2014, 05:38 PM
Thanks for the reply Princy.
So webusercontrol31 refers to the ID of the RadComboBox in ascx page? correct me if I am wrong because I tried
eventAdminRequired.ControlToValidate = eventAdminDropDown.DropDownToValidate.UniqueID; - > error ->
Does this statement have to be on the page load? because I want the validation to work on submit of the page.
eventAdminRequired.ControlToValidate = WebUserControl31.DropDownToValidate.UniqueID;
So webusercontrol31 refers to the ID of the RadComboBox in ascx page? correct me if I am wrong because I tried
eventAdminRequired.ControlToValidate = eventAdminDropDown.DropDownToValidate.UniqueID; - > error ->
Unable to find control id 'radcmbEmployeeSearch' referenced by the 'ControlToValidate' property of 'eventAdminRequired'.
eventAdminRequired.ControlToValidate = radcmbEmployeeSearch.DropDownToValidate.UniqueID; -> doesnt recognize "radcmbEmployeeSearch" field.Does this statement have to be on the page load? because I want the validation to work on submit of the page.
eventAdminRequired.ControlToValidate = WebUserControl31.DropDownToValidate.UniqueID;
0
Princy
Top achievements
Rank 2
answered on 24 Jan 2014, 02:58 AM
Hi,
yes, 'WebUserControl31' is the ID of the RadComboBox ASCXpage. In order to work RequiredFieldValidator you need to set the ControlToValidate property in either ASPX or Page_Load(). So please try tho set the ControlToValidate property in Page_Load(), and it will do the validation on the Button Click. Please have a look into the sample code snippet which works fine at my end.
ASPX:
ASPX C#:
ASCX:
yes, 'WebUserControl31' is the ID of the RadComboBox ASCXpage. In order to work RequiredFieldValidator you need to set the ControlToValidate property in either ASPX or Page_Load(). So please try tho set the ControlToValidate property in Page_Load(), and it will do the validation on the Button Click. Please have a look into the sample code snippet which works fine at my end.
ASPX:
<
uc1:WebUserControl3
ID
=
"WebUserControl31"
runat
=
"server"
/>
<
asp:RequiredFieldValidator
ID
=
"eventAdminRequired"
runat
=
"server"
ValidationGroup
=
"Group1"
ErrorMessage
=
"*"
>
</
asp:RequiredFieldValidator
>
<
telerik:RadButton
ID
=
"RadButton1"
runat
=
"server"
Text
=
"Submit"
ValidationGroup
=
"Group1"
>
</
telerik:RadButton
>
ASPX C#:
protected
void
Page_Load(
object
sender, EventArgs e)
{
eventAdminRequired.ControlToValidate = WebUserControl31.DropDownToValidate.UniqueID;
}
ASCX:
<
telerik:RadComboBox
ID
=
"radcmbEmployeeSearch"
runat
=
"server"
EmptyMessage
=
"select"
>
<
Items
>
<
telerik:RadComboBoxItem
Text
=
"Item1"
/>
<
telerik:RadComboBoxItem
Text
=
"Item2"
/>
<
telerik:RadComboBoxItem
Text
=
"Item3"
/>
<
telerik:RadComboBoxItem
Text
=
"Item4"
/>
</
Items
>
</
telerik:RadComboBox
>
ASCX C#:
Thanks,
Princy.
public
RadComboBox DropDownToValidate
{
get
{
return
radcmbEmployeeSearch;
}
}
Thanks,
Princy.
0
vvvv
Top achievements
Rank 1
answered on 24 Jan 2014, 05:10 PM
I tried the exact same way you followed and I get the following error Princy.
Here is the code at my end.
I am stuck with this for so long. Could this be handled in any other way?? I really appreciate your help.
Unable to find control id 'ctl00$ctl00$ContentPlaceHolder1$mainContent$body$radcmbEmployeeSearch$radcmbEmployeeSearch' referenced by the 'ControlToValidate' property of 'eventAdminRequired'.
.ASCX
-------
<
telerik:RadComboBox
ID
=
"radcmbEmployeeSearch"
runat
=
"server"
EmptyMessage
=
"Select Event Admin"
AllowCustomText
=
"true"
EnableLoadOnDemand
=
"true"
ShowMoreResultsBox
=
"true"
EnableVirtualScrolling
=
"true"
OnItemsRequested
=
"radcmbEmployeeSearch_ItemsRequested"
Height
=
"200px"
>
</
telerik:RadComboBox
>
.ASCX.CS
----------
public RadComboBox DropDownToValidate
{
get
{
return radcmbEmployeeSearch;
}
}
.ASPX
-------
<%@ Register Src="~/UserControls/EventAdminDropDown.ascx" TagPrefix="EAdm" TagName="DropDown" %>
<
tr
runat
=
"server"
>
<
td
>
Event Admin<
span
class
=
"Required"
>*</
span
>
</
td
>
<
td
runat
=
"server"
>
<
EAdm:DropDown
runat
=
"server"
ID
=
"radcmbEmployeeSearch"
/>
<
asp:RequiredFieldValidator
id
=
"eventAdminRequired"
runat
=
"server"
errormessage
=
"Required"
validationgroup
=
"group1"
>
</
asp:RequiredFieldValidator
>
</
td
>
</
tr
>
<asp:button id="btnCreate" runat="server" text="Create Event" onclick="btnCreateEvent_Click" validationgroup="group1" />
.ASPX.CS
---------
protected void Page_Load(object sender, EventArgs e)
{
eventAdminRequired.ControlToValidate = radcmbEmployeeSearch.DropDownToValidate.UniqueID;
}
I am stuck with this for so long. Could this be handled in any other way?? I really appreciate your help.
0
vvvv
Top achievements
Rank 1
answered on 27 Jan 2014, 06:10 AM
I need your help guys..Please let me know what I am doing wrong or any work around for this problem...
0
Accepted
Hello,
Please find attached a sample project that implements the approach that Princy posted in the very last response. The RadComboBox control is set as public property of the user control so it could be retrieved from the page that contains this user control.
Regards,
Boyan Dimitrov
Telerik
Please find attached a sample project that implements the approach that Princy posted in the very last response. The RadComboBox control is set as public property of the user control so it could be retrieved from the page that contains this user control.
Regards,
Boyan Dimitrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
0
vvvv
Top achievements
Rank 1
answered on 29 Jan 2014, 04:58 PM
Thanks for your reply. Where should I look for the attached project?
0
Hello,
Please find the project as a .zip file attached to my response.
Regards,
Boyan Dimitrov
Telerik
Please find the project as a .zip file attached to my response.
Regards,
Boyan Dimitrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.