asp.net后台如何获得前台控件的值 [英] asp.net 后台如何获得前台 控件的值
本文介绍了asp.net后台如何获得前台控件的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下边代码这种方式只能获得服务器控件,我想要获得HTML控件如何实现
下边代码这种方式只能获得 服务器控件,我想要获得HTML控件如何实现
foreach (Control c in form1.Controls)
{
if (c.GetType().ToString().Equals("System.Web.UI.HtmlControls.HtmlInputCheckBox"))
{
System.Web.UI.HtmlControls.HtmlInputCheckBox ch = (System.Web.UI.HtmlControls.HtmlInputCheckBox)c;
ch.Checked = true;
}
}
下面的代码以这种方式只能获取服务器控件,我想如何获取HTML控件?
The following code in this way can only get server control, I want to get HTML control how?
推荐答案
任何标记为runat="server"
的控件都可以在服务器上访问并按照您在问题中显示的方式进行处理.
如果未将其标记为作为服务器控件进行访问,则(默认情况下没有runat标记的常规HTML控件)无法在服务器端进行访问.
Any control marked asrunat="server"
can be accessed on the server side and handled as shown by you in the question.
If it''s not marked to be accessed as a server control, (general HTML controls that has no runat tag by default) cannot be accessed on the server side.
您好,
首先,请用英语写所有内容,因为不是每个人都可以读第一行(我也是;)).
关于您的问题:
如果要在服务器上的控件集合中获取HTML控件,则必须将其标记为runat="server"
.只有这样,它才能在控件集合中显示为ASP.NET控件.
另一个提示:如果要检查对象/控件是否具有特定类型,请不要比较Type.ToString!这样比较:
Hi,
First of all, please write everything in english, because not everyone can read the first line (me too ;)).
About your question:
If you want to get a HTML control in your controls collection on the server, you have to mark it asrunat="server"
. Only this way it would show up in the controls collection as a ASP.NET Control.
Another hint: if you want to check if a object / control is of a particular type, don''t compare the Type.ToString! Compare it this way:
if (c is System.Web.UI.HtmlControls.HtmlInputCheckBox) { ... }
希望这会有所帮助.
最好的问候,
停止
Hope this helps.
Best regards,
Stops
这篇关于asp.net后台如何获得前台控件的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文