locked
signup valdidation RRS feed

  • Question

  • User639567535 posted

    i have a signup form and also i apply validation

    when user fill all fields data save in database and this work fine but when user enter data and miss one field  e.g phone number or any other filed

    then click on signup button then this data alwasys save in database

    but i want when any user miss one r  two  or three fields then other data not save in database until user complete all fields

    here is signup code.

    protected void Btn_Save_Click(object sender, EventArgs e)
            {
                if (string.IsNullOrEmpty(txt_fullname.Value))
                {
                    LbelName.Text= "Please fill this";
                }
                else if(string.IsNullOrEmpty(txt_password.Value))
                {
                    LbelPass.Text="Please fill this";
                }
                else if(string.IsNullOrEmpty(txt_mail.Value))
                {
                    LbelEmail.Text="Please fill this";
                }
                else if(string.IsNullOrEmpty(txt_number.Value))
                {
                    LbelNumber.Text="Please fill this";
                }
     
                    
    
                    try
                    {
                        ab.Userssign(txt_fullname.Value,txt_password.Value,txt_mail.Value,txt_number.Value);
                        //cc.getusername(TextBox1.Text);
                        //sig.Text = ("Register Success");
                        Label5.Text = ("Signup Success");
                    }
                    catch
                    {
                        Label6.Text = ("SignUp failed");
    
                    }
                    txt_fullname.Value= "";
                   txt_password.Value = "";
                    txt_mail.Value = "";
                    txt_number.Value="";
                }
    
    
            }
        }

    and signup function

     public void Userssign(string username, string password, string email, string phonenumber)
            {
                db.ExecuteReader("spusersignup", new object[] { username, password, email, password });
            }


    Sunday, September 22, 2013 5:17 AM

All replies

  • User-1315512054 posted

    Hello,

    Actually you have checked the values and changed the textbox value. Whatever is the result you save it into the database.

    You could be example make a check, before saving into the database as:

    if (LbelNumber.Text !="Please fill this")

    i.e. if all the fields are not empty then save them into the database.

    You could also read this tutorial - http://www.howtoasp.net/asp-net-tutorials/how-to-use-requiredfieldvalidator-control-in-asp-net-4-0/.

    Regards

    Sunday, September 22, 2013 5:29 AM
  • User639567535 posted

    I done this but data always save in database and i dnt want this

    when all fileds all filed and click on sugnup button then data save in database other wise not...

    Sunday, September 22, 2013 5:41 AM