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

CustomValidator on GridCheckBox

3 Answers 172 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nancy Cara
Top achievements
Rank 1
Nancy Cara asked on 08 Feb 2008, 10:53 PM
Control 'ValidatePhoneIsPrimary' referenced by the ControlToValidate property of '' cannot be validated.

This is the error I get on my custom validator. If I change the validator to a different control to validate - like a textboxcontrol - then it works fine. But it won't work for my checkbox. 

<telerik:GridCheckBoxColumn HeaderText="Primary" DataType="System.Boolean" DataField="IsPrimary" CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" ForceExtractValue="None" UniqueName="PhoneIsPrimary">
<HeaderStyle Width="10px" />
</telerik:GridCheckBoxColumn>

protected void RadGrid1_ItemCreated1(object sender, GridItemEventArgs e)

{

if (e.Item.OwnerTableView.Name == "Phone")
    {
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            GridEditableItem item2a = e.Item as GridEditableItem;

GridCheckBoxColumnEditor editor2a = (GridCheckBoxColumnEditor)item2a.EditManager.GetColumnEditor("PhoneIsPrimary");

TableCell cell2a = (TableCell)editor2a.CheckBoxControl.Parent;

CustomValidator validator2a = new CustomValidator();

editor2a.CheckBoxControl.ID =

"ValidatePhoneIsPrimary";

validator2a.ControlToValidate = editor2a.CheckBoxControl.ID;

validator2a.ErrorMessage =

"Inactive or Closed Phone can not be Primary Phone";

validator2a.ServerValidate +=

new ServerValidateEventHandler(CustomValidator1_ServerValidate);

cell2a.Controls.Add(validator2a);

}}}

 

protected void CustomValidator1_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)

{

if (args.Value == "0"){args.IsValid = true;}}

If I can get this working I will also need to look at and compare args.value to my combobox dropdown selected value - I am not sure how to retrieve that value here in my validation routine.

3 Answers, 1 is accepted

Sort by
0
plamen
Top achievements
Rank 1
answered on 12 Feb 2008, 01:34 PM
0
Nancy Cara
Top achievements
Rank 1
answered on 13 Feb 2008, 08:39 PM
Unfortunately none of that information addresses my problem. I think it is a bug with trying to assign a validation event to a 

GridCheckBoxColumnEditor because like I said, it works fine for  GridTextBoxColumnEditor and GridMaskedColumnEditor

0
plamen
Top achievements
Rank 1
answered on 14 Feb 2008, 12:24 PM
hi

There are some server controls for which Custom validator can't be applied. CheckBox control is one such control. Custom validator eases the validation logic written by the developer. When I had a requirement in my project to validate the CheckBox control, I Googled and found the following article:

http://www.velocityreviews.com/forums/t560757-validating-checkboxes-on-the-clientside.html

http://www.syncfusion.com/FAQ/aspnet/WEB_c18c.aspx#q464q

Regards...
<John:Peel />
Tags
Grid
Asked by
Nancy Cara
Top achievements
Rank 1
Answers by
plamen
Top achievements
Rank 1
Nancy Cara
Top achievements
Rank 1
Share this question
or