Firing Click events and Reading IFrame Source of External URL in ASP.NET web form

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
 
S

Steven Cheng[MSFT]

Hi EJ,

Thanks for your reply. Since you mentioned that you failed to apply my
logic to workaround the loop sync problem, would you provide some detailed
info on why it fails or there is any other requirements prevent it ?

Also, I still think the simplest and convenient means is to call the next
element at the end of the previous element's document_complete event. As
for any other means, you may have a look at the WaitHandle class under the
Sytem.Threading namespace.

#WaitHandle Class
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemThreadingWaitH
andleClassTopic.asp?frame=true

#WaitHandle.WaitOne Method
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemThreadingWaitH
andleClassWaitOneTopic.asp?frame=true

It can help block the current thread for sync with another via a certain
signal.
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top