How to click a button on an ASP.NET web page programmatically?

前端 未结 9 1561
梦谈多话
梦谈多话 2021-02-09 09:57

I am trying to figure out how to click a button on a web page programmatically.

Specifically, I have a WinForm with a WebBrowser control. Once it navigates to the targe

相关标签:
9条回答
  • 2021-02-09 10:47

    var btn = document.getElementById(btnName); if (btn) btn.click();

    0 讨论(0)
  • 2021-02-09 10:48

    You could call the method directly and pass in generic object and EventArgs parameters. Of course, this might not work if you were looking at the sender and EventArgs parameters for specific data. How I usually handle this is to refactor the guts of the method to a doSomeAction() method and the event handler for the button click will simply call this function. That way I don't have to figure out how to invoke what is usually just an event handler to do some bit of logic on the page/form.

    In the case of javascript clicking a button for a form post, you can invoke form.submit() in the client side script -- which will run any validation scripts you defined in the tag -- and then parse the Form_Load event and grab the text value of the submit button on that form (assuming there is only one) -- at least that's the ASP.NET 1.1 way with which I'm very familiar... anyone know of something more elegant with 2.0+?

    0 讨论(0)
  • 2021-02-09 10:55

    There is an example of how to submit the form using InvokeMember here. http://msdn.microsoft.com/en-us/library/ms171716.aspx

    0 讨论(0)
提交回复
热议问题