开发者

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">&l开发者_高级运维t;/textarea>

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

Thanks.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜