All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET技巧:COOKIE问题_.net资料_编程技术
PHP新手总结的PHP基础知识_php资料_编程技术
用标准的SQL语句实现查询记录分页_[SQL,Server教程]
用php或js获取图片大小,高宽尺寸_[PHP教程]
AJAX技术在PHP开发中的简单应用_[AJAX教程]
ASP.NET技巧:脚本获取选中文字及所在句子_.net资料_编程技术
delphi单行编辑框组件(TEdit)使用实例
VS2008简体中文版下载(及升级为正式版办法,见截图)_[Asp.Net教程]
用VS.NET,2005重构你的代码_[Asp.Net教程]
C#中动作类型控件应用实例
Reading number is top 10 pictures
The money of more than 100 countries and regions9
西游四格漫画(二)
The household of rural style is designed
Wear bikinis cock
Absolutely shocked. National geographic 50 animal photographys8
From China fortress sora aoi3
壮丽的云彩1
职场回春术
Distribution of wealth in China survey status report
A resort photographed beautiful young woman change clothes process vomiting blood1
Download software ranking
Eclipse 4.2.2 For Win64
圣殿祭司的ASP.NET.2.0.开发详解-使用C#
C#COM编程指南
电车之狼R
C#程序员参考手册
I'm come from Beijing1
Tram sex maniac 2 (H) rar bag4
Tram sex maniac 2 (H) rar bag17
Be there or be square
Ashlynn Video3
delv published in(发表于) 2014/1/6 9:05:07 Edit(编辑)
ASP.Net防止刷新自动触发事件的解决方案_[Asp.Net教程]

ASP.Net防止刷新自动触发事件的解决方案_[Asp.Net教程]

ASP.Net防止刷新自动触发事件的解决方案_[Asp.Net教程]

使用asp.net,在刷新页面的时候会自动触发服务器端的事件。举个简单的例子,如:一个注册页面,我们填写完注册信息之后,如果按F5刷新之后,会自动触发到Button事件上,这样就造成了又注册了一次的麻烦。

  我先前的解决方案:用关键字查询,如有相同,则提示已有此用户。


  但是这种方案不能在没有表识的情况下使用,他会重新提交。鉴于此,我寻找了一种新的解决方案,很庆幸,在朋友的提点下,迸发了这样的解决方案,肯定有更好的解决方案,不吝赐教。


  解决思路:刷新时,捕捉KeyPress,让他触发其他无用的事件。


  1、捕捉F5事件的JavaScript


window.document.onkeydown = KeyStroke;
function KeyStroke()
{
var key = event.keyCode;
event.srcElement.releaseCapture();
if(key == 116)
{
document.getElementById("Button1").click();
event.keyCode=0;
event.returnValue=false;
}
}


  2、aspx页面放置一个Button


Text="Button">


  3、Button事件


private void Button1_Click(object sender, System.EventArgs e)
{
Response.Write( "You have pressed the key F5");
}


  这个“舍车保帅”的方案,能解决刷新自动触发事件的解决方案这个小问题,如果谁有更好的方案,希望告诉我一声,不胜感激!


来源:网络







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.