tags:

views:

42

answers:

1

I have a repeater with Remove buttons (LinkButton). Expensive database calls determine if a row can be removed (weird and not ideal, I know). In each row, I've got a CustomValidator that has a OnServerValidate event hander.

The problem is that I don't know which RepeaterItem the user is attempting to remove during the multiple calls to CustomValidator.OnServerValidate() event. If I had this information, I could filter the validation to the exact row the user is trying to remove.

For now, I've unsubscribed from CustomValidator.OnServerValidate and hacked it together so Repeater.OnItemCommand gathers the RepeaterItem and passes it into a validation method that sets CustomValidator.IsValid after the database validation. This works, but seems lame. There has got to be a way to keep my validation code in my validator.

Thanks in advance for any help.

A: 

You can get the RepeaterItem using the NamingContainer property of the button.

RepeaterItem item = (RepeaterItem)button.NamingContainer;
Ed D
In the context of CustomValidator.OnServerValidate(), "button" is not available if it's nested in the repeater items. Try it.
Robert H.
Why can't you just handle the button click event and get it from there?
Ed D
See the original post. That's what I'm doing. It works, but it sucks that the form "passed validation" already. Seems incorrect. working != correct
Robert H.