Click here to Skip to main content
15,900,699 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
OK all I am really confusing myself and anyone that has coded knows that if you work on something to long it feels like you keep doing the same thing over and over and you can't figure it out!

So anyways I have never used the webbrowser control with c# until now. I have it doing just about everything I want I want ... going to a page, pulling some data, parsing etc..

The page I am doing this on ha a datagrid with infomation in it, but has multiple pages (i.e. 1,2,3,4 Next> ) I am trying to cycle through these pages and collect data, but when I try to run my loop within my application it will load the initial page and then the last page in the loop.

I have read a couple things about using document complete event, but I am not sure I quite understand it.

Do I put the loop in this event ?

Can someone give me code example of how i might do this or point me in the right direction.

If you need me to post some code I can, but I have tried this so many ways now I am not sure even where I am on it!

I have been all over google and msdn and I just can't find a solution. I have seen where others have had this issues, but the question never comes to a conclusion.
Posted
Comments
aidin Tajadod 21-Feb-11 20:05pm    
Hi, As I understood, you just want to parse the webpage. if this is, why do'nt you use HttpWebRequest ?
chad777 22-Feb-11 16:11pm    
I am already parsing the page and i need to use the web browser control because this was request by a manager. I have everything the way it should except changing pages which is starting to be a pain in the.... well If I loop through an unknown number of pages (well unknown until my app counts them) it will go to the initial page on load and then the last page in the loop. I figure this is because the loop is not waiting for the page to load so it is overriding the the fire. so basically I know what is wrong I just don't know how to fix it and a timer does not seem to work.

Hi, maybe this link might guide you closer to your goal.
It has better handling for the events and it is also explained very well.

(here is it's introduction:
The WebBrowser control for .NET is just a wrapper for the IE ActiveX control. However this wrapper does not expose all the events that the IE ActiveX control exposes.

<a href="http://blogs.artinsoft.net/mrojas/archive/2008/09/18/newwindow2-events-in-the-c-webbrowsercontrol.aspx">http://blogs.artinsoft.net/mrojas/archive/2008/09/18/newwindow2-events-in-the-c-webbrowsercontrol.aspx</a>[<a href="http://blogs.artinsoft.net/mrojas/archive/2008/09/18/newwindow2-events-in-the-c-webbrowsercontrol.aspx" target="_blank" title="New Window">^</a>]

I used this quite a while ago so the memory isn't really fresh, but I can recall that at least this helped me with my event based problems concerning this control ;)

best regards
Andy
 
Share this answer
 
v3
This will provide a "loop" to wait until a new page is fully loaded. If I'm not mistaken, the browser control sends document complete messages for a number of things (image loads, etc), but the last one it sends its when the all objects are finished (including frames).

Not sure how this will behave with paging, but if they have different absolute addresses it should be fine.

C#
private void Browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    /** make sure we are only handling the event sent by the main url, not frames, etc **/
    if (!e.Url.AbsoluteUri.Equals(browser.Document.Url.AbsoluteUri))
    {
        return;
    }
}


Note: I cant remember where I got this snip, but credit is not mine
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900