0

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

3
Contributors
2
Replies
11
Views
4 Years
Discussion Span
Last Post by annaharris
0

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
    }
}

Edited by LastMitch: grammer

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.