How do I click an ASP.NET webform's button when the page is hosted in a WebBrowser Control

≡放荡痞女 提交于 2019-12-11 17:11:39

问题


I have a standard ASP.NET web form in a web page, and this page is hosted in a .NET Winform with a WebBrowser Control. Using c# how do I control the WebBrowser Control to submit the ASP.NET form? (eg somehow "clicking" on the button from the Winform?)

Update: to complicate things we have the ASP.NET validators which seem to make simple document.forms(0).submit() not work


回答1:


I answered a similar question. Check this : simulate Web Page keystroke

You can use the following code

WebBrowser1.Document.Forms("loginform").InvokeMember("submit");



回答2:


Because of the complication of the ASP.NET validators somehow messing with the normal form.submit() flow the submit button's click method had to be called:

WebBrowser1.Document.getElementById("mybutton").InvokeMember("click");


来源:https://stackoverflow.com/questions/1508091/how-do-i-click-an-asp-net-webforms-button-when-the-page-is-hosted-in-a-webbrows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!