|
-
Mar 14th, 2007, 12:00 PM
#1
Thread Starter
Member
[2.0] Strange problem with WebBrowser control "double loading" a page, eh?
This is a very strange problem I came across and it's a show stopper for my current app. It happens all the time on the site I'm trying to interact with and it occasionally happens on google.com (or any site I'd imagine).
I'm trying to run a series of events depending on what URL is currently being navigated.
In my WebBrowser's DocumentCompleted event I have a switch which runs a different set of methods based on the URL.
After a document is complete, it'll run the switch fine but it runs what's inside of the case I'm trying to detect more than once. It's easy to see by placing a messagebox output. It'll come up 2 times instead of once.
I tried other ways of determining which page I'm currently on. Like using the DocumentTitleChanged event instead of DocumentCompleted, but I think DocumentCompleted is safer because it won't do anything until the document is loaded. Either way, the problem exists with DocumentTitleChanged too.
Any ideas? Btw I excluded the site where it occurs all the time because it requires a login and unfortunately I can't share it publicly. If you want to do a test, just throw together an app really quick and drop a messagebox into the DocumentChanged event, then have a textbox where you can enter different addresses -- it's bound to come up.
-
Mar 15th, 2007, 07:27 AM
#2
Re: [2.0] Strange problem with WebBrowser control "double loading" a page, eh?
Look out for <meta http-equiv="refresh".../> tags that redirect you to the same page.
I don't live here any more.
-
Mar 15th, 2007, 08:07 AM
#3
Thread Starter
Member
Re: [2.0] Strange problem with WebBrowser control "double loading" a page, eh?
There are no meta-refesh tags in the page source. There's also no standard frames, just possibly "layers" inserted by javascript.
msdn says DocumentCompleted will fire off everytime a frame of a page is loaded. So if a page has 2 frames, it will trigger twice.
I have no idea how to get around this though. A possible solution was to use the DownloadBegin event to increment a counter by 1, then in the DocumentCompleted event decrease the counter by1 -- when it hits 0, the page should be in theory finished.
Problem is the Web Browser control does not have a DownloadBegin event. I tried this method using the Navigated method (adding to a counter) thinking it would be similiar to DownloadBegin but it apparently isn't the same thing. Neither is Navigating event.
Basically I just want to fire off my methods !once! when the page is totally finished loading regardless of how ever many frames/layers the page has. That is what I'm trying to produce and cannot.
To give you a better idea of what I'm doing, this is the logic of my app...
Here are the cases I look for and the actions that take place depending on which step (URL) I'm on:
At a login screen
-- automatically login
-- goto the search screen
At a search screen
-- search for xx (a number that the user of the app enters which gets auto-incremented)
-- determine if the search returned a result
---- if it did, then move on to the "scrape phase"
---- if it did NOT, go back to the search screen and log it
-- auto increment search number (here's the part where having it load twice is killing me)
At the Scrape phase (which is the same URL as the search screen except it has a "#search_result" in the URL)
-- Parse out 2 URLs from the search result and navigate to the first address
At first URL result
-- Check for xx (which is entered in my app but will be a constant in the session)
---- if it found it, move onto the second URL
---- if it did NOT find it, go back to the search page
At second URL result
-- Scrape a few pieces of information and store it into a DataSet
-- Go back to the search page and start over
I can't use the WebClient class because it requires slight user interaction due to a random character generator (on their site) coming up on various steps of the procedure. To counter that I check the page source for a specific string that only exists when this page is shown and I perform this check before I run the switch.
Last edited by ThisIsMyUserName; Mar 15th, 2007 at 08:12 AM.
-
Mar 15th, 2007, 01:01 PM
#4
Re: [2.0] Strange problem with WebBrowser control "double loading" a page, eh?
AllowNavigation = false;
the above is probably your best ally in the fight against the WebBrowser control. Experiment with setting it true or false at various times, results may vary depending on why you are trying to do.
I don't live here any more.
-
Mar 15th, 2007, 03:42 PM
#5
Thread Starter
Member
Re: [2.0] Strange problem with WebBrowser control "double loading" a page, eh?
I tried every combination of true/false I could think of (in various different areas of the program where it would make sense). It still loads the thing twice or it dies out before it processes the search. 
The Web Browser control cannot win. Any other ideas?
-
Mar 16th, 2007, 04:42 AM
#6
Thread Starter
Member
Re: [2.0] Strange problem with WebBrowser control "double loading" a page, eh?
Came up with a solution. Rather than increment the search param when the document loads, I now increment it when the user initiates the search (right before I send it to the web browser control).
The result is it works as intended, but I won't mark the thread as resolved as this is still a problem I'd like to eventually work out.
-
Mar 16th, 2007, 01:00 PM
#7
Re: [2.0] Strange problem with WebBrowser control "double loading" a page, eh?
What web address are you having problems with?
Please don't post any site address here that might be of questionable content (I'm sure you won't anyway but stranger things have happened over the years).
I don't live here any more.
-
Mar 17th, 2007, 03:27 AM
#8
Thread Starter
Member
Re: [2.0] Strange problem with WebBrowser control "double loading" a page, eh?
As stated in my first post I can't post the link (it's protected by a login that I cannot give out (work related)).
In theory any site that contains more than 1 frame should have a problem with the DocumentCompleted event firing once for each frame.
Edit:
Did a quick google and came across a random site that has frames.
Make a new Windows Application.
Add a Web Browser control
Use: http://www.stephen.com/mondrimat/ as the url
In the DocumentCompleted event add:
MessageBox.Show("DocumentCompleted fired!");
The site I'm having trouble with doesn't have frames like this, but it does use a means of adding content to a page that's considered a frame to the Web Browser control. The end result is the same though.
Last edited by ThisIsMyUserName; Mar 17th, 2007 at 03:38 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|