Asp.Net清空页面所有textbox的几种方法总结
Asp.Net清空页面所有textbox的几种方法总结
在Asp.Net中清空所有textbox有好几种方法,本文提供几种,供大家参考!
foreach( Control childControl in this.Controls )
{
if( childControl is TextBox )
((TextBox)childControl).Text = "";
}
}
foreach( Control childControl in this.Controls )
{
if( childControl is TextBox )
((TextBox)childControl).Text = "";
}
}
用反射:
FieldInfo[] infos = GetType().GetFields( BindingFlags.Public | BindingFlags.NonPublic|BindingFlags.GetField |BindingFlags.Instance);
for(int i=0;i<infos.Length;i++)
{
if(infos[i].FieldType == typeof(TextBox))
{
((TextBox)infos[i].GetValue(this)).Text = "";
}
}
//使用javascript,好处是不用刷新页面:
function ClearAllTextBox()
{
var obj=window.document.forms[0];
for(i=0;i<obj.elements.length; i++)
{
var elem=obj.elements[i];
if(elem)
{
if(elem.type=="text")
{
elem.value="";
}
}
}
}
//最后一种用Jquery
function ClearText() {
$("input").each(function() {
$(this).val('');
});
}
相关文档:
asp.net自动生成静态页面代码
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
......
* Copyright all(c) 2005 ZhongFeng, http://blog.csdn.net/SW515 */
public class ValidateCode : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
this.CreateCheckCodeImage(GenerateCheckCode());
}
&nb ......
http://www.codeproject.com/KB/aspnet/ASPDOTNETPageLifecycle.aspx?msg=3443071#xx3443071xx
ASP.NET application and page life cycle
Introduction
The Two step process
Creation of ASP.NET environment
Process request using MHPM events fired
In What event we should do what?
A sample code for demons ......
最近做网站用到了上传控件,找到了一个界面比较好看的 Uploadify
看到别人的文章学会使用 。原文地址:
http://doc.chinaunix.net/web/201001/304549.shtml
不是转帖,自己写写自己的。一个完整的解决方案。包括文件上传,文件信息获取和显示,语言:C#
Upload.aspx //上传主页--主要是配置 jquery. ......