I have a formview which holds a form with an edit and insert modes. On the insert I would like a custom validator set against the userid text box that on the insert will check the database and see if it already exists, if it does it won't insert if it doesnt it will. the code that was already in place uses formview_itemInserting and formview_ItemInserted then a method customVal_ServerValidate. In this method I've already establised a connection to the db and i am storing the exisiting ID in a payroll if it exists. I am then using an if statement to check if the id entered matches existing id. Not sure how to get it not to insert if it already exists. The code for the methods are

  protected void fv_ItemInserting(object sender, FormViewInsertEventArgs e)
        {

            e.Values["InputUserId"] = Context.User.Identity.Name;
            e.Values["date"] = System.DateTime.Now;

            UpdatePanelgv.Update();
        }

        protected void fv_ItemInserted(object sender, FormViewInsertedEventArgs e)
        {
            if (e.Exception == null)
            {

                UpdatePanelgv.Update();
                gv.DataBind();
                fv.ChangeMode(FormViewMode.ReadOnly);
                ModalPopupExtenderInsert.Hide();

                //set success panel details
                pnlSuccess.Visible = true;
                lblSuccess.Text = "A new user has been created";
                lblSuccessHeading.Text = "User  created";
            }
        }

           protected void cusValtb_ServerValidate(object source, ServerValidateEventArgs args)
        {
            TextBox newUser = (TextBox)fv.FindControl("UserTextBox");


            String User = newUser.Text;  
            user a = (User)userManager.userGetByID(User);
            String existID = a.User;

            args.IsValid = (newUser.Text == existID);

            //if true insert CRM
            if (args.IsValid == true)
            {

            }

            else
            {

            } 
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.