清空页面上的所有TextBox中的文本

zizilovejava 2009-04-29 05:07:28
protected void Condition(Control ctrl)
{
for (int i = 0; i < this.Controls[1].Controls.Count; i++)
{
if (this.Controls[1].Controls[i] is TextBox)
{
((TextBox)this.Controls[1].Controls[i]).Text = "";
}
}
}

protected void Button2_Click(object sender, EventArgs e)
{
Condition(this);
}

清空不了呀
...全文
214 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
lijianqiang 2009-04-30
  • 打赏
  • 举报
回复
Condition(this); 这样写不对
改成 Condition(this. Controls);
zizilovejava 2009-04-30
  • 打赏
  • 举报
回复
To YxFlyBee

产生System.InvalidCastException异常
无法将类型为“ASP.masterpage_master”的对象强制转换为类型“System.Windows.Forms.Control”。
zzxap 2009-04-29
  • 打赏
  • 举报
回复
[code=C#]
public static void TextClear(System.Web.UI.Page p)
{
string js;
js ="< language='java'>";
js +="var mm = getElementsByTagName('input').length ;";
js +="for(var i=0;i<mm;i++)";
js +="{";
js += "var dd = getElementsByTagName('input').item(i);";
js += "if(dd.type == 'text')";
js += "{";
js += "dd.='';";
js += "}";
js +="}";
js +="</scr"+"ipt>";
p.RegisterStartup("ms",js);
}
[/CODE]
xlsdan 2009-04-29
  • 打赏
  • 举报
回复
   
protected void Condition()
{
foreach (Control c in this.FindControl("form1").Controls)
{

if (c is TextBox)
{

((TextBox)c).Text = "";

}

}

}
protected void Button2_Click(object sender, EventArgs e)
{
Condition();
}
harderLi 2009-04-29
  • 打赏
  • 举报
回复
Condition(Page);
A海阔天空 2009-04-29
  • 打赏
  • 举报
回复

稍微一下设置为空就可以了

//设置界面上控件的Enable为false,并且设置TextBox的边框样式
public static void SetChildControlsReadOnlyPropertyAndBorderStyle(Control parentControl, bool isReadOnly ) {
int i;
DropDownList tempDropDownList;
TextBox tempTextBox;
CheckBox tempCheckBox;
if (parentControl == null) return;
for (i = 0; i < parentControl.Controls.Count; i++)
{
if (parentControl.Controls[i].GetType().Name == "TextBox")
{
tempTextBox = (TextBox)parentControl.Controls[i];
tempTextBox.ReadOnly = isReadOnly;
tempTextBox.ForeColor = Color.Black;
}
if (parentControl.Controls[i].GetType().Name == "DropDownList")
{
tempDropDownList = (DropDownList)parentControl.Controls[i];
tempDropDownList.Enabled = !isReadOnly;
}
if (parentControl.Controls[i].GetType().Name == "CheckBox")
{
tempCheckBox = (CheckBox)parentControl.Controls[i];
tempCheckBox.Enabled = !isReadOnly;
}
}
}
zgke 2009-04-29
  • 打赏
  • 举报
回复
private void button2_Click(object sender, EventArgs e)
{
Condition();
}

protected void Condition()
{
foreach (Control _Control in this.Controls)
{
Condition(_Control);
}

}

protected void Condition(Control p_Control)
{
if (p_Control is TextBox)
{
p_Control.Text = "";
return;
}
foreach (Control _Control in p_Control.Controls)
{
Condition(_Control);
}
}

这样看看.
FlyBee 2009-04-29
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 YxFlyBee 的回复:]
protected void Button2_Click(object sender, EventArgs e)
{
Condition(this);
} [/Quote]
Condition(); this不要复制错了
levinstong 2009-04-29
  • 打赏
  • 举报
回复
((TextBox)this.Controls[1].Controls[i]).Text = string.Empty ; 

把改在这样试试看
gciyfzx07 2009-04-29
  • 打赏
  • 举报
回复
protected void Condition(Control ctrl)
{
for (int i = 0; i < this.Controls[1].Controls.Count; i++)
{
if (Typeof(this.Controls[1].Controls[i]) is TextBox)
{
((TextBox)this.Controls[1].Controls[i]).Text = "";
}
}
}
FlyBee 2009-04-29
  • 打赏
  • 举报
回复
 protected void Condition()
{
foreach (System.Windows.Forms.Control control in this.Controls)
{
if (control is System.Windows.Forms.TextBox)
{
System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)control;
tb.Text = "";
}
}
}

protected void Button2_Click(object sender, EventArgs e)
{
Condition(this);
}
PandaIT 2009-04-29
  • 打赏
  • 举报
回复
foreach (Control Ctrol in this.Controls) 
{
if (Ctrol is TextBox)
{
Ctrol.Text = "";
}
}


FlyBee 2009-04-29
  • 打赏
  • 举报
回复
foreach (System.Windows.Forms.Control control in this.Controls)
{
if (control is System.Windows.Forms.TextBox)
{
System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)control;
tb.Text = "";
}
}

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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