Link to home
Start Free TrialLog in
Avatar of DColin
DColinFlag for Thailand

asked on

Passing aruments to the DocumentCompleted event of a WebBrowser control

Hi Experts,

How to I pass an argument to the DocumentCompleted event of a WebBrowser control. The DocumentComplete event is called automatically so I do not get to write the values I want to pass into the event arg list. Thanks.
Avatar of Slow_mo
Slow_mo

What and why do you need to pass? DocumentCompleted event is raised when control finishes loading a document. I don't quite understand, what data do you need as an event argument.
ASKER CERTIFIED SOLUTION
Avatar of kblau
kblau

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What I posted adds another event where you can add additional event arguments.  I agree with slow mo that this probably does not buy you anything.  Kudos for being observant about the event firing in code that we have no control over even with overriding.  You can check out google: download reflector vb.net c#

Please note that an Event is just a keyword that sets t he scope of a delegate to be more secure - see Juval Lowy Components book
Avatar of DColin

ASKER

Hi Slow mo,

I want to do something like the attached code. When the page has loaded auto fill the email address in a form, but how do I pass the Email address string to the DocumentCompleted event. Thanks.
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
 
   Dim Email as string
        'WebBrowser1.Document.GetElementsByTagName("input").GetElementsByName("emailaddress").Item(0).SetAttribute("value", Email)
 
    End Sub

Open in new window

So if I understand you correctly, you need to fill the textbox on your windows form based on the data in web page. Why do you need data in web page to be passed as an event argument? Can't you just access it from the WebBrowser1 object after the DocumentCompleted event is raised?

Anyway, if you really need it as an argument, I would create a wrapper class for WebBrowser object that would have a custom event with a data you need. In this case your class catches DocumentCompleted event, retreives an e-mail from the web page and raises event with this e-mail as an argument.
I *think* they have an Email string and, when the webpage loads, set the value of a textbox inside the webpage to that email. Where is the Email coming from? Can't you just use a local variable?