如何通过 CSharp 以编程方式设置输入元素的值? [英] How Do You Set Value of Input Element Programmatically Through CSharp?
本文介绍了如何通过 CSharp 以编程方式设置输入元素的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好我正在尝试使我的 IE 自动化以登录网站,但问题是输入元素没有 HTML ID 属性!例如:
Hello I am trying to automate my IE to log into a website but the problem is that the input elements do not have an HTML ID attribute! For example:
如何编写 C# 程序在此文本框中插入文本?
How do you program C# to insert text in this text box?
谢谢
推荐答案
将以下属性添加到您的输入标签:runat="server"
和 id="someId"
Add the following attributes to your input tag: runat="server"
and id="someId"
<input id="user" type="text" size="15" runat="server">
然后是服务器端:
user.Text = "sample text";
然后您可以执行以下操作:
Then you can do something like:
foreach (Control c in Page.Controls)
{
TextBox t = c as TextBox;
if (t != null)
{
t.Text = "sample text";
}
}
但我不确定它是否会在没有 runat="server"
属性的情况下工作
But I'm not sure it'll work without the runat="server"
attribute
这篇关于如何通过 CSharp 以编程方式设置输入元素的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文