alexbartell

I have a Windows app in C#/ VB with webBrowser control in it in which the web page is being displayed. When the user enteres his address information and hit "Submit" button, I want to get that whole data/info entered by user before it is sent to the server (post is being used to send data to server).
Is there an event in WebBrowser which gets fired when the html data is sent to the Server. Is there a way to get that information before it get sent to the server.

thanks



Re: Internet Explorer Web Development How to get html code in C# from webBrowser before it get submit to the Server ?

Avi29

There is an event called Navigating which occurs before page is loaded inside web browser control. If you want to access html elements itself then you need to handle DocumentCompleted event which is triggered after page is loaded.



Re: Internet Explorer Web Development How to get html code in C# from webBrowser before it get submit to the Server ?

alexbartell

thanks for replying. I really appreciate your kindness.

Here is what I I tried.

In code after form_load() when user click on the hyperlink "continue" I want to access the data inputted by user in the textfield 'userName' . As you mentioned I agree that I could access html elements in "webBrowser1_DocumentCompleted" but could NOT access the VALUES of the textfield which is CRUCIAL for me. Any Ideas

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace alex

{

public partial class Form1 : Form

{

public event WebBrowserNavigatingEventHandler navigating;

public Form1()

{

InitializeComponent();

}

private void form1_Load(object sender, EventArgs e)

{

webBrowser1.DocumentText = "<html><body>Please enter your name:<br/>" +

"<input type='text' name='userName'/><br/>" +

"<a href='http://www.microsoft.com'>continue</a>" +

"</body></html>";

webBrowser1.Navigating += new WebBrowserNavigatingEventHandler(webBrowser1_IDontKnow);

}

private void webBrowser1_IDontKnow(object sender, WebBrowserNavigatingEventArgs e)

{

//MessageBox.Show(webBrowser1.DocumentStream.ToString ());

MessageBox.Show(webBrowser1.DocumentText );

}

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)

{

MessageBox.Show(webBrowser1.DocumentText);

}

}

}





Re: Internet Explorer Web Development How to get html code in C# from webBrowser before it get submit to the Server ?

Avi29

Attach onclick event to link element.

private void webBrowserSecured_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)

{

HtmlElement btn = WebBrowser1.Document.GetElementById("Button1") as HtmlElement;

btn.AttachEventHandler("onclick", new EventHandler(ButtonClicked));

}

private void ButtonClicked(object sender, EventArgs e)

{

string txt1 = ((mshtml.HTMLInputElementClass)(WebBrowser1.Document.GetElementById("TextBox1").DomElement)).IHTMLInputElement_value;

}

WebBrowser1.Document.GetElementById("ElementId").DomElement gives the element type.