如何提取表单N个控件名

shenshanlaoguai 2004-10-30 01:13:49
题目也不知道写的对不对,我的意思是这样的:

在ASP中的A.ASP页面中假设有如下代码
<form name=form1 method=post action=B.asp>
......
<input type=text name=table1>
<input type=text name=table2>
<input type=text name=table3>
<input type=text name=table4>
......
</form>

在B.asp中
<%
......
for each element to request.form(element)
if instr(element,"table")>0 then response.write element & "<br>"
next
......
%>
这样就可以把A.asp页中控件名称包含table的控件名都显示在页面上了。

现在我想知道在ASP.NET中如何做到。
...全文
136 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
shenshanlaoguai 2004-10-30
  • 打赏
  • 举报
回复
呜呜呜呜呜呜……你们太让我感动了^Q^
风林火山的我测试了,好用。
goody9807给出的是VB的吧?这事怨我没说清楚,我需要C#的。不管怎么,分我是要给的。
非常感谢你们二位,解决了我的问题。
再次表示感谢!
veaven 2004-10-30
  • 打赏
  • 举报
回复
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面

string strText ="";
foreach(System.Web.UI.Control control in this.Page.Controls)
{
strText += GetControls(control,"");
}
Response.Write(strText);
}

private string GetControls(Control control,string pre)
{
string str = pre+ "type:"+control.GetType().Name+" id:" + control.ID +"<br>";
foreach(System.Web.UI.Control ctrl in control.Controls)
{
str += GetControls(ctrl,pre+"--");
}
return str;
}
goody9807 2004-10-30
  • 打赏
  • 举报
回复
For each control in Page.Controls(1).Controls
if typeof control is TextBox then
dim t as TextBox
t=ctype(control,TextBox)
response.write(t.name)
End if

next

veaven 2004-10-30
  • 打赏
  • 举报
回复
在你的页面类中的Page.Controls
里面包含了全部的control
用control.id 便可以的到名称
用control的type 类型就可以得到是什么控件


62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧