How to press a button using encoding?

I have two buttons in my program, and I want the second button to be pressed automatically when the first button is pressed (in the event handler of the first button, I want to press the second button using encoding).

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") && 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; } } } 
+4
source share
3 answers

I think you are describing that you want to call a method when you press button B, but then also call this method when button A is pressed.

 protected void ButtonA_Click(...) { DoWork(); } protected void ButtonB_Click(...) { // do some extra work here DoWork(); } private void DoWork() { // do the common work here } 

Depending on your implementation in event handlers, you can also simply call the second button event handler from the first, but the specified path is the "right" way to do this.

+5
source

You can just call the method.

  private void btnA_Click(object sender, EventArgs e) { doA(); } private void doA() { //A stuff } private void btnB_Click(object sender, EventArgs e) { doA(); doB(); } private void doB() { //B stuff } 

Or call the _Click method directly;

  private void btnB_Click(object sender, EventArgs e) { btnA_Click(sender, e); doB(); } 
+2
source

I think you don’t care whether the button is pressed or not, you just need the second button code to be executed. So ... just call it:

 void button1_Click(...) { button2_Click(...); } 
+1
source

Source: https://habr.com/ru/post/1346575/


All Articles