CustomValidator in Repeater

G

Guest

Hi,

I have a Repeater where each row (Repeater item) contains a Checkbox and two
Textboxes. The first Textbox has a RequiredFieldValidator and everything work
fine. The other should only validate if the Chekbox is checked. To achieve
this I've added a CustomValidator, set the ControlToValidate to the id of the
Textbox and set a OnServerValidate handler. But once the OnServerValidate
code behind method fires I can't find a good solution on how to find the
checkbox in that Repeater item.

Any ideas?

protected void valReqErrorMessage_ServerValidate(object source,
ServerValidateEventArgs args)
{
//Only validate args.Value if "chb" is selected ... ?
}

Thanks in advance

Richard
 
Joined
Nov 9, 2006
Messages
3
Reaction score
0
Try this,

The source should be validator, sitting on the RepeaterItem, get to it via the Parent and then find the checkbox control.

i.e.

CheckBox checkBox = ((RepeaterItem)((Control)source).Parent).FindControl("chb");

where "chb" is the id of your checkbox

Chris.-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top