使用 C# 自动填充网页上的 2 个字段

编程入门 行业动态 更新时间:2024-10-26 08:24:08
本文介绍了使用 C# 自动填充网页上的 2 个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 C#(Microsoft Visual C# 2010 Express)开发一个简单的 Web 表单应用程序.

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

我在表单上有两个文本框(textBox1、richTextBox1)、一个按钮(button1)和一个网络浏览器(webBrowser1).当我运行程序时,Web 浏览器会转到一个网页.在该页面上有两个输入字段,我想通过使用 textBox1 和 richTextBox1 中的文本单击 button1 来自动填充.

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>

我知道这很简单,但我对 C# 了解不多.任何想法如何编码?

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

谢谢.

推荐答案

你需要写这个代码

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

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

并且需要调用这两行Webbrowser 的 DocumentCompleted 事件.

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

希望有帮助.

更多推荐

使用 C# 自动填充网页上的 2 个字段

本文发布于:2023-11-07 17:19:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567014.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   网页

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!