0

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
            {

            } 
        }
2
Contributors
1
Reply
19
Views
4 Years
Discussion Span
Last Post by LastMitch
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.