title: RequiredFieldValidator not working if I put a code in the button's Click property ASP.NET
body: <p>Q: All the RequiredFieldValidators are working when I make the btnSubmitCheckup_Click property empty. But if I put a simple code inside it, the validators are not working anymore and more, it will execute the simple code I placed inside the Click property of the button.</p>
  
  <p>How will prevent the program from going forward if the required fields are blank? I've set the ControlToValidate and it works flawlessly when there is no code inside the btnSubmitCheckup_Click but if I try to put a code inside it, it will go forward and disregard the RequiredFieldValidator.</p>
  
  <pre><code>protected void btnSubmitCheckup_Click(object sender, EventArgs e)
          {
              Response.Write("asdasda"); ////will work even all other textboxes are empty but validators won't appear
              //_con.Open();
              //SqlCommand NewCheckup = new SqlCommand("dbo.NewCheckup", _con);
              //NewCheckup.CommandType = CommandType.StoredProcedure;
              //NewCheckup.Parameters.Add("@PatientID", SqlDbType.Int).Value = RadioButtonList_Patient.SelectedValue;
              //NewCheckup.Parameters.Add("@DeptCode", SqlDbType.VarChar).Value = RadioButtonList_Department.SelectedValue;
              //NewCheckup.Parameters.Add("@EmpID", SqlDbType.Int).Value = RadioButtonList_Employee.SelectedValue;
              //NewCheckup.Parameters.Add("@CheckupDate", SqlDbType.Date).Value = BasicDatePicker1.SelectedDate;
              //NewCheckup.Parameters.Add("@Diagnosis", SqlDbType.VarChar).Value = txtDiagnosis.Text;
              //NewCheckup.ExecuteNonQuery();
              //_con.Close();
              //Response.Write("&lt;script&gt;Alert('Checkup Successfully recorded!')&lt;/script&gt;");
          }
  </code></pre>
  
  <p>This is my source</p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="NewCheckup.aspx.cs" Inherits="Clinic_WebDev.NewCheckup" %&gt;
  
  &lt;%@ Register assembly="BasicFrame.WebControls.BasicDatePicker" namespace="BasicFrame.WebControls" tagprefix="BDP" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;Bargamed Clinic - New Checkup&lt;/title&gt;
      &lt;style type="text/css"&gt;
          .style1
          {
              width: 100%;
          }
          .style2
          {
              width: 136px;
          }
          .style3
          {
              width: 250px;
          }
          #TextArea1
          {
              height: 104px;
              width: 272px;
          }
      &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;table class="auto-style1"&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/InsertProcedure.aspx"&gt;Insert Procedure&lt;/asp:HyperLink&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/InsertPatient.aspx"&gt;Insert Patient&lt;/asp:HyperLink&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="~/InsertEmployee.aspx"&gt;Insert Employee&lt;/asp:HyperLink&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:HyperLink ID="HyperLink4" runat="server" NavigateUrl="~/InsertDepartment.aspx"&gt;Insert Department&lt;/asp:HyperLink&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:HyperLink ID="HyperLink5" runat="server" NavigateUrl="~/NewCheckup.aspx"&gt;New Checkup&lt;/asp:HyperLink&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
      &lt;/table&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;table class="style1"&gt;
          &lt;tr&gt;
              &lt;td align="right" bgcolor="#66FF66" class="style2"&gt;
                  Name of Patient&lt;/td&gt;
              &lt;td bgcolor="#CCFFCC" class="style3"&gt;
                  &lt;asp:TextBox ID="txtPatientName" runat="server" AutoPostBack="True" 
                      TextMode="Search" Width="170px"&gt;&lt;/asp:TextBox&gt;
              &lt;/td&gt;
              &lt;td bgcolor="#66FF66" style="margin-left: 80px"&gt;
                  Press Enter to search a patient
                  &lt;br /&gt;
                  &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" 
                      ControlToValidate="txtPatientName" ErrorMessage="Please search for a patient" 
                      Font-Italic="True" Font-Names="Segoe UI" ForeColor="#666633" 
                      EnableClientScript="False"&gt;&lt;/asp:RequiredFieldValidator&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td align="right" bgcolor="#66FF66" class="style2"&gt;
                  Patient&lt;/td&gt;
              &lt;td bgcolor="#CCFFCC" class="style3"&gt;
                  &lt;asp:RadioButtonList ID="RadioButtonList_Patient" runat="server" 
                      AutoPostBack="True" DataSourceID="SqlDataSource3" DataTextField="PatientName" 
                      DataValueField="PatientID"&gt;
                  &lt;/asp:RadioButtonList&gt;
                  &lt;asp:SqlDataSource ID="SqlDataSource3" runat="server" 
                      ConnectionString="&lt;%$ ConnectionStrings:CLINICConnectionString %&gt;" 
                      SelectCommand="SELECT PatientID, FirstName + ' ' + MiddleName + ' ' + LastName AS PatientName FROM PATIENT WHERE (FirstName + ' ' + MiddleName + ' ' + LastName LIKE '%' + @PatientName + '%')"&gt;
                      &lt;SelectParameters&gt;
                          &lt;asp:ControlParameter ControlID="txtPatientName" Name="PatientName" 
                              PropertyName="Text" /&gt;
                      &lt;/SelectParameters&gt;
                  &lt;/asp:SqlDataSource&gt;
              &lt;/td&gt;
              &lt;td bgcolor="#66FF66"&gt;
                  &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" 
                      ControlToValidate="RadioButtonList_Patient" 
                      ErrorMessage="Please select the patient" Font-Italic="True" Font-Names="Segoe UI" 
                      ForeColor="#666633"&gt;&lt;/asp:RequiredFieldValidator&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td align="right" bgcolor="#66FF66" class="style2"&gt;
                  Department
              &lt;/td&gt;
              &lt;td bgcolor="#CCFFCC" class="style3"&gt;
                  &lt;asp:RadioButtonList ID="RadioButtonList_Department" runat="server" 
                      AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="DeptName" 
                      DataValueField="DeptCode" 
                      onselectedindexchanged="RadioButtonList_Department_SelectedIndexChanged"&gt;
                  &lt;/asp:RadioButtonList&gt;
                  &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                      ConnectionString="&lt;%$ ConnectionStrings:CLINICConnectionString %&gt;" 
                      SelectCommand="SELECT DeptCode, DeptName, Status FROM DEPARTMENT"&gt;
                  &lt;/asp:SqlDataSource&gt;
              &lt;/td&gt;
              &lt;td bgcolor="#66FF66"&gt;
                  &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                      ControlToValidate="RadioButtonList_Department" 
                      ErrorMessage="Please select the department" Font-Italic="True" 
                      Font-Names="Segoe UI" ForeColor="#666633"&gt;&lt;/asp:RequiredFieldValidator&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td align="right" bgcolor="#66FF66" class="style2"&gt;
                  Employee&lt;/td&gt;
              &lt;td bgcolor="#CCFFCC" class="style3"&gt;
                  &lt;asp:RadioButtonList ID="RadioButtonList_Employee" runat="server" 
                      DataSourceID="SqlDataSource2" DataTextField="EmpName" DataValueField="EmpID"&gt;
                  &lt;/asp:RadioButtonList&gt;
                  &lt;asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                      ConnectionString="&lt;%$ ConnectionStrings:CLINICConnectionString %&gt;" 
                      SelectCommand="SELECT EmpID, EmpName, EmpStatus, Contact FROM EMPLOYEE WHERE (EmpID IN (SELECT EmpID FROM EMPLOYEE_SPECIALIZATION WHERE (DeptCode LIKE @DeptCode)))"&gt;
                      &lt;SelectParameters&gt;
                          &lt;asp:ControlParameter ControlID="RadioButtonList_Department" 
                              DefaultValue="None" Name="DeptCode" PropertyName="SelectedValue" /&gt;
                      &lt;/SelectParameters&gt;
                  &lt;/asp:SqlDataSource&gt;
              &lt;/td&gt;
              &lt;td bgcolor="#66FF66"&gt;
                  &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                      ControlToValidate="RadioButtonList_Employee" 
                      ErrorMessage="Please select the employee" Font-Italic="True" 
                      Font-Names="Segoe UI" ForeColor="#666633"&gt;&lt;/asp:RequiredFieldValidator&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td align="right" bgcolor="#66FF66" class="style2"&gt;
                  &lt;asp:Label ID="Label1" runat="server" Text="Date of Checkup"&gt;&lt;/asp:Label&gt;
              &lt;/td&gt;
              &lt;td bgcolor="#CCFFCC" class="style3"&gt;
                  &lt;BDP:BasicDatePicker ID="BasicDatePicker1" runat="server" /&gt;
              &lt;/td&gt;
              &lt;td bgcolor="#66FF66"&gt;
                  &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                      ControlToValidate="BasicDatePicker1" 
                      ErrorMessage="Please select the date of checkup" Font-Italic="True" 
                      Font-Names="Segoe UI" ForeColor="#666633"&gt;&lt;/asp:RequiredFieldValidator&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td align="right" bgcolor="#66FF66" class="style2"&gt;
                  &lt;asp:Label ID="Label2" runat="server" Text="Diagnosis"&gt;&lt;/asp:Label&gt;
              &lt;/td&gt;
              &lt;td bgcolor="#CCFFCC" class="style3"&gt;
                  &lt;asp:TextBox ID="txtDiagnosis" runat="server" Height="67px" 
                      TextMode="MultiLine" Width="247px"&gt;&lt;/asp:TextBox&gt;
              &lt;/td&gt;
              &lt;td bgcolor="#66FF66"&gt;
                  &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                      ControlToValidate="txtDiagnosis" ErrorMessage="Please put the diagnosis" 
                      Font-Italic="True" Font-Names="Segoe UI" ForeColor="#666633" 
                      ValidationGroup="ValidationGroupDaw"&gt;&lt;/asp:RequiredFieldValidator&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td bgcolor="#66FF66" class="style2"&gt;
                  &amp;nbsp;&lt;/td&gt;
              &lt;td align="center" bgcolor="#CCFFCC" class="style3"&gt;
                  &lt;asp:Button ID="btnSubmitCheckup" runat="server" 
                      onclick="btnSubmitCheckup_Click" PostBackUrl="~/NewCheckup.aspx" 
                      Text="Submit Checkup" CausesValidation="False" 
                      ValidationGroup="ValidationGroupDaw" /&gt;
              &lt;/td&gt;
              &lt;td bgcolor="#66FF66"&gt;
                  &amp;nbsp;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td bgcolor="#66FF66" class="style2"&gt;
                  &amp;nbsp;&lt;/td&gt;
              &lt;td bgcolor="#CCFFCC" class="style3"&gt;
                  &amp;nbsp;&lt;/td&gt;
              &lt;td bgcolor="#66FF66"&gt;
                  &amp;nbsp;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>