Autofill 2 Fields on a Web Page with C#

最后都变了- 提交于 2019-12-06 17:05:49

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5907516/autofill-2-fields-on-a-web-page-with-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!