[英]add a event DocumentCompleted to a WebBrowser in c#
I want to add a event DocumentCompleted to my control WebBrowser. 我想将事件DocumentCompleted添加到控件WebBrowser中。 This is my code.
这是我的代码。 but it doesn't work.
但这不起作用。
<asp:Button id="Button_Auth" Text="Authentification" OnClick="Authentification_Click" runat="server"/> <asp:label id="Messages" runat="server"/>
public void Authentification_Click(object sender, EventArgs e)
{
string input = "https://www.google.fr";
runBrowserThread(input );
Messages.Text = "ok";
}
private void runBrowserThread(String url)
{
var th = new Thread(() => {
var br = new WebBrowser();
br.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
br.Navigate(url,true);
});
th.SetApartmentState(ApartmentState.STA);
th.Start();
}
public void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
var br = sender as WebBrowser;
Messages.Text = e.Url.ToString();
}
What I want is open a new page webBrowser and everytime when the page(in the case https://www.google.fr
)finishes loading, For example, User enter a key word and search it. 我想要的是打开一个新页面webBrowser,每次页面加载完成(例如
https://www.google.fr
)时,例如,用户输入关键字并搜索它。 when the page of result finishes loading, I will get back the url of result https://www.google.fr/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=keyword
and display it in my label Messages. 当结果页面完成加载后,我将返回结果
https://www.google.fr/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=keyword
并将其显示在标签消息。
I don't know why my code doesn't work. 我不知道为什么我的代码不起作用。
Check whether the event is right fully wierd to your event handler. 检查事件是否完全适合您的事件处理程序。
Is it a asp.net application or is it winforms application or wpf application? 它是asp.net应用程序,还是winforms应用程序或wpf应用程序? In asp.net application this event is not available.
在asp.net应用程序中,此事件不可用。 If asp.net try JavaScript
如果asp.net尝试JavaScript
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.