title: How to click a button through coding?
body: <p>I have two buttons in my program and i want that when i press first button the second button is clicked automatically ( in the event handler of first button , i want to press the second button through coding).</p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
      {
  
          passWord = pwd.Text;
          user = uName.Text;
  
  
          loginbackend obj = new loginbackend();
          bool isValid = obj.IsValidateCredentials(user, passWord, domain);
          if (isValid)
          {
              loginbackend login = new loginbackend();
              passWord = pwd.Text;
  
              login.SaveUserPass(passWord);
              HtmlDocument webDoc = this.webBrowser1.Document;
              HtmlElement username = webDoc.GetElementById("__login_name");
              HtmlElement password = webDoc.GetElementById("__login_password");
  
              username.SetAttribute("value", user);
              password.SetAttribute("value", passWord);
  
              HtmlElementCollection inputTags = webDoc.GetElementsByTagName("input");
  
              foreach (HtmlElement hElement in inputTags)
              {
                  string typeTag = hElement.GetAttribute("type");
                  string typeAttri = hElement.GetAttribute("value");
  
                  if (typeTag.Equals("submit") &amp;&amp; typeAttri.Equals("Login"))
                  {
                      hElement.InvokeMember("click");
  
                      break;
                  }
              }
              button3_Click(sender, e);
              label1.Visible = false ;
              label3.Visible = false;
              uName.Visible = false;
              pwd.Visible = false;
              button1.Visible = false;
              button2.Visible = true;
      }
           else 
          {
              MessageBox.Show("Invalid Username or Password");
          }
  
      }
  private void button3_Click(object sender, EventArgs e)
      {
          HtmlDocument webDoc1 = this.webBrowser1.Document;
          HtmlElementCollection aTags = webDoc1.GetElementsByTagName("a");
  
          foreach (HtmlElement link in aTags)
          {
              if (link.InnerText.Equals("Show Assigned"))
              {
                  link.InvokeMember("click");
                  break;
              }
          }
      }
  </code></pre>