yenren
yenren

Reputation: 522

Autofill 2 Fields on a Web Page with C#

I am working on a simple web forms application with C# (Microsoft Visual C# 2010 Express).

I have two text boxes (textBox1, richTextBox1) a button (button1) and a web browser (webBrowser1) on the form. The web browser goes to a web page when I run the program. On that page there are two input fields that I want to autofill with the click of the button1 using the text in textBox1 and richTextBox1.

You can see the code of the input fields on that web page:

<input type="text" id="subject" tabindex="4" name="subject" value="">

<textarea class="composebody" tabindex="6" name="message" id="message" rows="20" cols="80"></textarea>

I know this is very simple, but I don't have much knowledge about C#. Any ideas how I can code that?

Thanks.

Upvotes: 0

Views: 4051

Answers (2)

AjayR
AjayR

Reputation: 4179

You need to write this code

webBrowser1.Document.GetElementById("subject").SetAttribute("value", subject.text); webBrowser1.Document.GetElementById("msg").SetAttribute("value",message.text );

and need to call those two lines in DocumentCompleted event of webbrowser.

Hope it helps.

Upvotes: 2

IAmTimCorey
IAmTimCorey

Reputation: 16755

I believe you are looking for the following:

subject.value = "Your info here";

This will solve the issue for your first item but the text area is a bit more tricky. You will probably need to include some HTML item inside the text area that you can write to. I was not able to find a good way to write to the textarea item easily. If possible, I would suggest using a different control.

Upvotes: 0

Related Questions