views:

357

answers:

1

Hi,

In a C# WebBrowser control, I have generated a SELECT HtmlElement with a number of OPTION elements using w.RenderBeginTag(HtmlTextWriterTag.Select).

I need to get the value of the select when the user changes it, and so added an event handler in the WebBrowser DocumentCompleted event.

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    ....

    webBrowser1.Document.GetElementById("id_select_0").AttachEventHandler("onchange", new EventHandler(ddSelectedIndexChanged));
    ....
}

protected void ddSelectedIndexChanged(object sender, EventArgs e)
{
    ....
}

The event handler does get called, but the sender parameter is null and e is empty. Does anyone know how to overcome this problem?

Andrew

A: 

It is not possible get the event parameters from the DHTML event because the event handler is the general EventHandler class. Alternative way is to get the parameters from IHTMLEventObj, this object contains the same event parameters as HtmlElementEventArgs:

private void Element_OnChange(object sender, EventArgs e)
{
    IHTMLEventObj ev = (webBrowser1.Document.Window.DomWindow as IHTMLWindow2).@event;
}
volody