[英]Same webpage always loads with webBrowser
I have a program that I wrote for sending messages to some of my friends through a website. 我有一个程序可以通过网站发送消息给一些朋友。 It works fine, but for some reason I can't get it to work correctly with just one button click event.
它工作正常,但是由于某些原因,我仅通过一个按钮单击事件就无法使其正常工作。 If I don't have a second button click for the SEND data method (whichs POSTs the data), it will always just keep sending the message to the same person, eventhough the new URL is loaded into the webBrowser URL*, but if I have that second click event all works fine.
如果没有第二个按钮单击SEND数据方法(即POST数据),即使将新URL加载到webBrowser URL *中,它也始终将消息发送给同一个人,但是如果我再次点击事件一切正常。 What am I missing?
我想念什么?
*Using the debugger I see a new URL load with every iteration, but I do see on the HTTP debugger that the program is sending to the same URL each time *使用调试器,每次迭代我都会看到一个新的URL加载,但是我确实在HTTP调试器上看到该程序每次都发送到相同的URL
private void button1_Click(object sender, EventArgs e)
{
ListBox();
}
private void ListBox()
{
//gets name from ListBox
GetData();
}
private void GetData()
{
webBrowser1.Navigate(inputURLID);
//SendData (); Always sends to the same person if I call from here, so I made a second button click and it works fine
}
private void button2_Click(object sender, EventArgs e)// works fine like this
{
webBrowser1.Document.GetElementById("subject").SetAttribute("value", textBox2.Text);//To (username)
webBrowser1.Document.GetElementById("message").SetAttribute("value", richTextBox1.Text);//Subject
webBrowser1.Document.GetElementById("Submit").InvokeMember("click");//Message
}
.... ....
private void SendData()// always sends to the same person if I just do it like this
{
webBrowser1.Document.GetElementById("subject").SetAttribute("value", textBox2.Text);//To (username)
webBrowser1.Document.GetElementById("message").SetAttribute("value", richTextBox1.Text);//Subject
webBrowser1.Document.GetElementById("Submit").InvokeMember("click");//Message
}
Try to populate your fields only when the url has been loaded (when DocumentCompleted
event is fired): 尝试仅在加载了URL时(触发
DocumentCompleted
事件时)填充字段:
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.GetElementById("subject").SetAttribute("value", textBox2.Text);//To (username)
webBrowser1.Document.GetElementById("message").SetAttribute("value", richTextBox1.Text);//Subject
webBrowser1.Document.GetElementById("Submit").InvokeMember("click");//Message
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.