In a repeater, how can determine the RepeaterItem of the button clicked during a CustomValidator OnServerValidate event?
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 Re开发者_运维知识库peater.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.
You can get the RepeaterItem using the NamingContainer property of the button.
RepeaterItem item = (RepeaterItem)button.NamingContainer;
精彩评论