Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Forms WinForm
Hey guys,
When I'm working with webbrowser and I want to let my application navigate to url and for example click a button right after that how should I do that? The problem is that my apps always perform all the commands too quickly and it mostly ends up with my app not being able to find the element by id because web page is still not loaded. Well I tried to use timers and it seems to work but when I'm trying to do apps which I need to navigate on more webpages, then clicking the buttons I just get too many timers and its confusing. I'm pretty sure there must be some way to make some kind of delay to wait until the page loads, then execute the commands. Already tried DocumentCompleted event based on webbrowser's url but it seems to create infinite loop. I was thinking about Sleep() but it makes your app freeze for certain time so that's propably not what I'm looking for. I have no idea how to solve this issue without creating that many timers. Can anybody please help?
Posted 3-Apr-13 10:09am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

IF course, any kinds of delay for a fixed amount of times are completely pointless, not just slow.
 
It looks like you need to handle the event System.Windows.Forms.WebBrowser.DocumentCompleted:
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documentcompleted.aspx[^].
 
Alternatively, to get the same effect, override the virtual method System.Windows.Forms.WebBrowser.OnDocumentCompleted:
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.ondocumentcompleted.aspx[^].
 
"After navigation" may be not what you want (but of course, there is an appropriate event you can handle), because it is invoked at the moment of time when a document only starts to load.
 
—SA
  Permalink  
v3

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

  Print Answers RSS
0 OriginalGriff 584
1 Maciej Los 275
2 DamithSL 233
3 Sergey Alexandrovich Kryukov 209
4 BillWoodruff 200
0 OriginalGriff 6,803
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,421
3 Manas Bhardwaj 4,841
4 Maciej Los 4,330


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 3 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100