S
Steven Cheng[MSFT]
Hi EJ,
Thanks for the followup. I've read the code you provided and also perform
some tests on my side regarding on the question in your last reply. Here is
my suggestion:
Since the WebBrowser control's Document_Complete event is async , I think
we'd better not use foreach or for (...) to
loop through the collections. My solution is
1.when the Main page is completed download or rendered and then loopthrough
all those links and put them in a Array( a class member of the winform
control class so that we can retrieve it in all the functions). Also, put
another int member to store the current_index in the array. Call the
Array[0].click() and set the current_index = 0
2. Then in the DocumentComplete event, if it is the iframe docuemtn be
completely loaded, check the current_index,
if not end of the Array, then increase it by 1 and call the click method of
the current_index item. such as
if(current_index < templinks.Length-1)
{
current_index++;
Array[current_index].click();
}
So the complete DocumentComplete event is like below:
#templinks is the Array of the certain HTMLElement class member
#current_index is the member store the current html element's index
private void axWB_DocumentComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
string url = (string)e.uRL;
if(url.IndexOf("ListFrame.aspx") != -1)
{
IHTMLDocument2 HTMLDocument = (IHTMLDocument2) axWB.Document;
IHTMLElementCollection links = HTMLDocument.links;
templinks = new HTMLAnchorElementClass[links.length];
int i = 0;
foreach (HTMLAnchorElementClass el in links)
{
templinks = el;
i++;
}
current_index = 0;
templinks[current_index].click();
}
else if(url.IndexOf("IFramePage.aspx") != -1)
{
MessageBox.Show("SimpleIndexPage.aspx");
if(current_index < templinks.Length-1)
{
current_index++;
templinks[current_index].click();
}
}
}
Thus, we can make sure that we won't call the next element's click() before
the previous one has been loaded and operated yet.
How do you think of this? If you have anything unclear, please feel free to
post here. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Thanks for the followup. I've read the code you provided and also perform
some tests on my side regarding on the question in your last reply. Here is
my suggestion:
Since the WebBrowser control's Document_Complete event is async , I think
we'd better not use foreach or for (...) to
loop through the collections. My solution is
1.when the Main page is completed download or rendered and then loopthrough
all those links and put them in a Array( a class member of the winform
control class so that we can retrieve it in all the functions). Also, put
another int member to store the current_index in the array. Call the
Array[0].click() and set the current_index = 0
2. Then in the DocumentComplete event, if it is the iframe docuemtn be
completely loaded, check the current_index,
if not end of the Array, then increase it by 1 and call the click method of
the current_index item. such as
if(current_index < templinks.Length-1)
{
current_index++;
Array[current_index].click();
}
So the complete DocumentComplete event is like below:
#templinks is the Array of the certain HTMLElement class member
#current_index is the member store the current html element's index
private void axWB_DocumentComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
string url = (string)e.uRL;
if(url.IndexOf("ListFrame.aspx") != -1)
{
IHTMLDocument2 HTMLDocument = (IHTMLDocument2) axWB.Document;
IHTMLElementCollection links = HTMLDocument.links;
templinks = new HTMLAnchorElementClass[links.length];
int i = 0;
foreach (HTMLAnchorElementClass el in links)
{
templinks = el;
i++;
}
current_index = 0;
templinks[current_index].click();
}
else if(url.IndexOf("IFramePage.aspx") != -1)
{
MessageBox.Show("SimpleIndexPage.aspx");
if(current_index < templinks.Length-1)
{
current_index++;
templinks[current_index].click();
}
}
}
Thus, we can make sure that we won't call the next element's click() before
the previous one has been loaded and operated yet.
How do you think of this? If you have anything unclear, please feel free to
post here. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx