I have a gridview that stores information about items - a number and a name, I have a custom validator set agains t to check the number doesn't already exist in the database to prevent duplication.

   protected void CustomValTBCodeServerValidate(object source, ServerValidateEventArgs args)
        {
            TextBox newCode = (TextBox)fvCode.FindControl("TbCode");

            String XCode = newCode.Text;
            X a = (X)XManager.XGetByCode(XCode);
            String existCode = a.XCode;



            args.IsValid = (XCode != existCode);

            if (args.IsValid == true)
            {
                pnlSuccess.Visible = true;
            }

            else
            {
                pnlFail.Visible = true;
            }
        }

However this is preventing me from updating the record as the number already exists, I need it to allow the row i'm updating to update with the code and text if the current code only exists once.

Anyone any ideas?

Thanks

Member Avatar

LastMitch

Anyone any ideas?

You can look at this (it's just an idea):

protected void CustomValTBCodeServerValidate(object source, ServerValidateEventArgs args)
{
    String XCode = newCode.Text;
    if (XCode == string.Empty)
    {
        args.IsValid = false;  // field is empty
    }
    else
    {
        // used your custom validator here
    }
}

If it already exists in your table, that means the record has been duplicated. First remove the duplicacy issue.