title: ASP.NET Button OnClientClick
body: <p>I have question and any help will be greatly appreciated.  I hope I am explaining this clearly, but if i'm not just let me know, i will be on for a while.  This is written in C# and I have a button that calls a javascript function called "JavaScript()" in the "OnClientClick" part and in the "OnClick" part I have an "if statement" where the first part resembles the OnClientClick function and the second part represents different code that is not related to the OnClientClick.  </p>
  
  <p>DefaultPage.aspx:</p>
  
  <pre><code>&lt;asp:Button ID="Button1" runat="server" Text="Button" 
   OnClick="Button1_OnClick" 
   OnClientClick="JavaScript()"  /&gt;
  </code></pre>
  
  <p>DefaultPage.aspx.cs:</p>
  
  <pre><code>protected void Button1_OnClick(object sender, EventArgs e)
     {
    String a = getValueofA();
  
    If (a == "1")
    {
              //OnClientClick code goes here
    }
    else If (a == "2")
    {
       //No OnClientClick code goes here
    }
   }
  </code></pre>
  
  <p>This javascript function comes from a different Web Control that I am loading on this "DefaultPage".  This worked perfect for me until I added the "if statement" in Button1_OnClick.  Originally I just had the first part of the "if statement", now I need to add the second part of it.  How can I accomplish this.  I tried button1.OnClientClick, but it only works in Page_Load.  I need to first determine the value of "a" then proceed.  Sorry if i'm not clear but i can answer any questions.  Thanks so much.  My goal is to remove the "OnClientClick=JavaScript" from my asp.net button and just call that function inside the if statement.</p>