1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<script type="text/javascript"> //<![CDATA[ var theForm = document.forms['aspnetForm']; if (!theForm) { theForm = document.aspnetForm; } function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } } //]]> </script> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
// 假設 webBrowser 是你的 WebBrowser 控制項 string eventTarget = "YourEventTarget" ; // 替換成你的事件目標 string eventArgument = "YourEventArgument" ; // 替換成你的事件參數 // 確保網頁已經載入 if (webBrowser.ReadyState == WebBrowserReadyState.Complete) { // 呼叫 JavaScript 函數 webBrowser.Document.InvokeScript( "__doPostBack" , new object [] { eventTarget, eventArgument }); } else { // 網頁尚未載入完成,可以考慮加入事件監聽器 webBrowser.DocumentCompleted += (sender, e) => { webBrowser.Document.InvokeScript( "__doPostBack" , new object [] { eventTarget, eventArgument }); }; } |