ASP.NET中防止页面多次提交的代码实现
此处提供的代码用来实现当asp.net页面中的某个Button被点击后disable掉该页面中所有的Button,从而防止提交延时导致的多次提交。基于之前的onceclickbutton脚本.
//ASP.NET中防止页面多次提交的代码:javascript< script language="javascript"> < !-- function disableOtherSubmit()
{
var obj = event.srcElement;
var objs = document.getElementsByTagName('INPUT');
for(var i=0; i< objs.length; i++)
{
if(objs[i].type.toLowerCase() == 'submit')
{
objs[i].disabled = true;
}
}
} //--> < /script>//ASP.NET中防止页面多次提交的代码:asp.netpublic class PreventMultiClick : System.Web.UI.Page {
protected System.Web.UI.WebControls.Button Button1; protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.LinkButton LinkButton1; protected System.Web.UI.WebControls.Button Button3; private void Page_Load(object sender, System.EventArgs e)
{
this.GetPostBackEventReference(this.Button3);
//保证 __doPostBack(eventTarget, eventArgument) 正确注册 if(!IsPostBack)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("if (typeof(Page_ClientValidate) == 'function')
{
if (Page_ClientValidate() == false)
{
return false;
}
}"); //保证验证函数的执行 sb.Append("if(window.confirm('are you sure?')==false) return false; ");
//自定义客户端脚本 sb.Append("disableOtherSubmit(); ");
// disable所有submit按钮 sb.Append(this.GetPostBackEventReference(this.Button3));
//用__doPostBack来提交,保证按钮的服务器端click事件执行 sb.Append(";
相关文档:
3 mistakes to avoid when using jQuery with ASP.NET AJAX
AJAX, ASP.NET, JavaScript, jQuery By Dave Ward on June 5th, 2008
Over the past few weeks, I think I have definitely embodied Jeff Atwood’s claim that we’re all amateurs, learning together. Despite my best efforts to thoroughly tes ......
using (con)
{
con.Open();
String sqltext = "select * from emp where empno=@empno";
......
在ASP.NET应用程序常常会遇到需要从Excel文件中读取数据或将数据写入Excel的需求。一般来讲,在ASP.NET中读写Excel文件有四种解决方案。
1.1.1 使用OLE DB
使用OLE DB可以以查询数据库的方式来读取Excel文件,因为在某种程度上Excel表格可以看成是一张一张的数据表。其二者的主要区别在于所使用的数据引擎不一样。使用OLE ......
ASP.NET页面刷新方法总结
先看看ASP.NET页面刷新的实现方法:
第一:
private void Button1_Click(objectsender,System.EventArgse)
{
Response.Redirect(Request.Url.ToString());
}
第二:
private void Button2_Click(objectsender,System.EventArgse)
{
Response.Write("<mce:script language=javascript& ......
1.对象初始化(OnInit方法)
页面中的控件(包括页面本身)都是在它们最初的FORM中被首次初始化的。通过在ASPX页面的后台代码文件的构造器中声明你的对象,页面将知道对象的类型,并知道需要创建多少个这样的对象。一旦你在构造器中声明了你的控件,你就可以在它的任何子类,方法,事件或者属性中访 ......