I have a case in which I need to use a custom validator in a grid edit form, and part of the custom validation is dependent upon ID of the data item being edited, but I don't see how to find that data item in my validation code. Basically, I need to ensure that the name value entered in a text box is unique in the database for that table - which means that for an insert no other record should exist in the table with that name value, and for an update only the record with the matching ID should exist with that value. My custom validator looks like:
<asp:CustomValidator ID="UniqueNameValidator" runat="server" Display="Dynamic" ErrorMessage='A record already exists with this name' ControlToValidate="NameEditTextBox" OnServerValidate="ValidateUniqueName" />
Then the server side method would be:
protected void ValidateUniqueName(object source, ServerValidateEventArgs args)
{
/// code here
}
My problem is that the args object only gives me the value of the field being validated. In order for me to do the dupe check I need to know the GridEditableItem being edited, and I don't know how to find that programmatically in this case because I don't have a GridCommandEventArgs or similar object with which to look at e.Item.
Is there any way to find the current GridEditableItem object from just looking at the grid object? Or is there another way to approach this that I am missing?
<asp:CustomValidator ID="UniqueNameValidator" runat="server" Display="Dynamic" ErrorMessage='A record already exists with this name' ControlToValidate="NameEditTextBox" OnServerValidate="ValidateUniqueName" />
Then the server side method would be:
protected void ValidateUniqueName(object source, ServerValidateEventArgs args)
{
/// code here
}
My problem is that the args object only gives me the value of the field being validated. In order for me to do the dupe check I need to know the GridEditableItem being edited, and I don't know how to find that programmatically in this case because I don't have a GridCommandEventArgs or similar object with which to look at e.Item.
Is there any way to find the current GridEditableItem object from just looking at the grid object? Or is there another way to approach this that I am missing?