如何设置输入单元编程的价值通过CSHARP? [英] How Do You Set Value of Input Element Programmatically Through CSharp?
本文介绍了如何设置输入单元编程的价值通过CSHARP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好
我想我的自动化IE浏览器登录到网站,但问题是输入元素没有一个HTML ID属性!例如:
<输入类型=文本名称=用户大小=15值=>
如何编程C#中插入该文本框中的文本?
感谢
解决方案
添加以下属性添加到输入标签: =服务器
和 ID =someId
<输入ID =用户类型=文字大小=15=服务器>
<$:
然后服务器端你做p $ p> user.Text =示范文本;
然后,你可以这样做:
的foreach(在Page.Controls控制C)
{
文本框T = C作为文本框;
如果(T!= NULL)
{
t.Text =示范文本;
}
}
但我不知道它会不会工作在 =服务器
属性
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:
<input type="text" name="user" size="15" value="">
How do you program C# to insert text in this text box?
Thanks
解决方案
Add the following attributes to your input tag: runat="server"
and id="someId"
<input id="user" type="text" size="15" runat="server">
Then server-side you do:
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";
}
}
But I'm not sure it'll work without the runat="server"
attribute
这篇关于如何设置输入单元编程的价值通过CSHARP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文