问题
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