电脑技术学习

Asp.Net中带图片的重填按钮

admin
把我做第一次做系统时对重填按钮的实现记录如下:

第一次用ImageButton可以设置背景图片,然后在后台的Click事件中写如下

this.TxtCallNo.Text;=;"";
this.TxtCaller.Text;=;"";
this.TxtTranDate.Text;=;"";
this.TxtTranLimit.Text;=;"";
this.TxtTranNo.Text;=;"";
this.TxtTranPres.Text;=;"";
this.RadioButton1.Checked;=;false;
this.RadioButton2.Checked;=;false;
this.DlstUnit.SelectedIndex;=;0;

第二次也是用ImageButton,在Click事件中如下写:

foreach;(Control;c;in;form1.Controls)
{
if;(c;is;TextBox)
((TextBox)c).Text;=;"";
if;(c;is;DropDownList)
((DropDownList)c).SelectedIndex;=;0;
if;(c;is;RadioButton)
((RadioButton)c).Checked;=;false;
}

第三次是用<a;href="#"><img;src="images/but2.gif";width="61";onclick="ReSet();";/>
用JavaScript写ReSet()方法:

function;ReSet()
{
var;len=document.form1.elements.length;
var;i;
for;(i=0;i<len;i++)
{
if;(document.form1.elements[i].type=="text")
{
document.form1.elements[i].value="";;
}
if(document.form1.elements[i].type=="radio")
{
document.form1.elements[i].checked=false;
}
}
var;obj1=document.getElementById("DlstCallerWay");
var;obj5=document.getElementById("TxtRemark");
obj5.value="";
obj1.selectedIndex=0;
//不能获得DropDownList;的客户端type,不知道怎么获得的JS没学过。
//当文本框的TextMode设为multiline时也不能获得type就只能一个按照ID获得
}

这三种方法都是清空不是重置或重填,因为有时重置的要求是控件内有数据单击重置按钮后仍保留原来的数据,例如TextBox1加载页面时的值为“胡帅”,单击后仍是“胡帅”,上面的方法单击后都清空了。

标签: