遍历表单 bool flag = false; foreach (Control c in Page.FindControl("form1").Controls) { if (c is LiteralControl) { LiteralControl lc = c as LiteralControl; string temp_text = lc.Text; if (temp_text.Contains("input")) { flag = true; break; } } }
To 7 8楼是表单提交过来,按钮事件.request.form["inputname"]这种只是调用方法,不是判断是不是存在.如果不存在这个inputname的话,request.form["inputname"]这句话就会报错..悲催的没看到回复,我已经改用笨一点的方法了....不过我觉得5楼的遍历比较靠谱.回头试试.
foreach (Control c in Page.FindControl("form1").Controls)
{
if (c is LiteralControl)
{
LiteralControl lc = c as LiteralControl;
string temp_text = lc.Text;
if (temp_text.Contains("input"))
{
flag = true;
break;
} } }
如果是页面第一次加载,当然是不可能知道的