I have two buttons in a page. The function of the first button(Button3) is to send a confirmation mail to the mail ID in the first Textbox1. The function of second button(Button4) is to insert values into a database from textbox3 and textbox4 . I kept a required field validator for the first textbox(textbox1). So if I leave it blank and press Button3, it shows warning message that field cannot be left blank. But if the click Button4 even then it shows the same warning message that the field cannot be blank beside textbox1. Why is that so? How can I restrict the validation only for Button3 but not for the Button4?
Here's my C# code to make u understand what exactly I am talking about.
protected void Button3_Click(object sender, EventArgs e)
{
MailMessage objMail = new MailMessage("[email protected]", TextBox1.Text, "confirm", TextBox2.Text);
NetworkCredential objNC = new NetworkCredential("[email protected]", "mypassword");
SmtpClient objsmtp = new SmtpClient("smtp.gmail.com", 587);
objsmtp.EnableSsl = true;
objsmtp.Credentials = objNC;
objsmtp.Send(objMail);
}
protected void Button4_Click(object sender, EventArgs e)
{
try
{
String sCon = "SERVER=xyz;DATABASE=xyz;UID=xyz;password=xyz";
MySqlConnection con = new MySqlConnection(sCon);
MySqlCommand command = con.CreateCommand();
command.CommandText = "insert into criminals values('"+TextBox3.Text +"','"+ TextBox4.Text + "')";
con.Open();
command.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
}