title: Fire Custom Validator Before Processing Other Code
body: <p>I have the following in my .aspx file:</p>
  
  <pre><code>    &lt;asp:CustomValidator
          ID="JobIDCustomFieldValidator"
          runat="server"
          ControlToValidate="JobID"
          OnServerValidate="jobIDCustom_ServerValidate"
          EnableClientScript="false"
          SetFocusOnError="true"
          Display="Dynamic"
          ErrorMessage="! - Not Found"
          CssClass="validationError"&gt;
     &lt;/asp:CustomValidator&gt;
     &lt;br /&gt;        
     &lt;asp:TextBox ID="JobID" runat="server"&gt;&lt;/asp:TextBox&gt;
     &lt;asp:Button runat="server" ID="ProcessButton"  Text="Process" onclick="ProcessButton_Click" /&gt;
  </code></pre>
  
  <p>I have the following in my code behind file:</p>
  
  <pre><code>    protected void ProcessButton_Click(object sender, EventArgs e)
      {
          Response.Write("I am in here");
      }
  
      protected void jobIDCustom_ServerValidate(object sender, ServerValidateEventArgs e)
      {
          // Impersonate a user for shared folder access.
          using (UserImpersonation user = new UserImpersonation(properties.ShareUser, properties.Domain, properties.SharePassword))
          {
              e.IsValid = false;
  
              // Check the user credentials.
              if (user.ImpersonateValidUser())
              {
                 e.IsValid = File.Exists(@"\\\\" + properties.RemoteServer + "\\" + properties.Share + "\\" + JobID.Text + ".dat");
              }
          }
      }
  </code></pre>
  
  <p>I want the custom validator to be checked first and if it is false stop and do not run any of the code in the ProcessButton_Click() method. Is this possible?  If not is there an alternative way I could set this up?</p>
  
  <p>As far as I know I can't use client side validation with javascript to do the impersonating and file access.</p>
  
  <p>Any help would be greatly appreciated.</p>