Insted of void use return a boolean that is true or false so here is how it goes
private bool checkError()
{
if (txtName.Text == string.Empty)
{
WebMsgBox.Show("Please Enter User Name");
txtName.Focus();
return false;
}
if (txtUserId.Text.Trim() == string.Empty)
{
WebMsgBox.Show("Please Enter UserId");
txtUserId.Focus();
return false;
}
if (txtPasword.Text.Trim() == string.Empty)
{
WebMsgBox.Show("Please Enter Password");
txtPasword.Focus();
return false;
}
else return true;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
if(checkError())
{
SqlConnection con = database.GetConnection();
SqlCommand com = new SqlCommand("spRegistration", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@Name", txtName.Text);
com.Parameters.AddWithValue("@UserId", txtUserId.Text);
com.Parameters.AddWithValue("@Password", txtPasword.Text);
com.Parameters.AddWithValue("@Date", txtDate.Text);
com.ExecuteNonQuery();
WebMsgBox.Show("Accounts Created Successfully");
clearFields();
}
}
catch (Exception ex)
{
WebMsgBox.Show("Error Message:" + ex.Message);
}
}