ajax 防止用户反复提交的2种解决方案
程序员文章站
2022-05-28 12:29:21
可在服务器端加载方法: 复制代码 代码如下: private void onloading() { system.text.stringbuilder sb = new s...
可在服务器端加载方法:
private void onloading()
{
system.text.stringbuilder sb = new system.text.stringbuilder();
sb.append(" function pageload(){var manager = sys.webforms.pagerequestmanager.getinstance(); ");
sb.append(" manager.add_beginrequest(onbeginrequest); manager.add_endrequest(onendrequest)} var lcpostbackelementid;");
sb.append(" function onbeginrequest(sender, args){ lcpostbackelementid = args.get_postbackelement().id.tolowercase(); if (lcpostbackelementid === \"btnadwords\"){$get(\"btnadwords\").disabled = true; $get(\"btnadwords\").value='正在提交...';}} ");
sb.append(" function onendrequest(sender, args){if (lcpostbackelementid === \"btnadwords\"){ $get(\"btnadwords\").disabled = false; $get(\"btnadwords\").value='确定';}} ");
scriptmanager.registerstartupscript(page, page.gettype(), "btnadwords", sb.tostring(), true);
}
也可直接写在页面脚本里:
<script>
function pageload()
{
var manager = sys.webforms.pagerequestmanager.getinstance();
manager.add_beginrequest(onbeginrequest);
manager.add_endrequest(onendrequest)
}
var lcpostbackelementid;
function onbeginrequest(sender, args)
{
lcpostbackelementid = args.get_postbackelement().id.tolowercase();
if (lcpostbackelementid === 'btnadwords')
{
$get('btnadwords').disabled = true;
$get('btnadwords').value='正在提交...';
}
}
function onendrequest(sender, args)
{
if (lcpostbackelementid === \"btnadwords\")
{
$get('btnadwords').disabled = false;
$get('btnadwords').value='确定';
}
}
< /script>
更多内容请参考:http://msdn.microsoft.com/zh-cn/magazine/cc163319.aspx
复制代码 代码如下:
private void onloading()
{
system.text.stringbuilder sb = new system.text.stringbuilder();
sb.append(" function pageload(){var manager = sys.webforms.pagerequestmanager.getinstance(); ");
sb.append(" manager.add_beginrequest(onbeginrequest); manager.add_endrequest(onendrequest)} var lcpostbackelementid;");
sb.append(" function onbeginrequest(sender, args){ lcpostbackelementid = args.get_postbackelement().id.tolowercase(); if (lcpostbackelementid === \"btnadwords\"){$get(\"btnadwords\").disabled = true; $get(\"btnadwords\").value='正在提交...';}} ");
sb.append(" function onendrequest(sender, args){if (lcpostbackelementid === \"btnadwords\"){ $get(\"btnadwords\").disabled = false; $get(\"btnadwords\").value='确定';}} ");
scriptmanager.registerstartupscript(page, page.gettype(), "btnadwords", sb.tostring(), true);
}
也可直接写在页面脚本里:
复制代码 代码如下:
<script>
function pageload()
{
var manager = sys.webforms.pagerequestmanager.getinstance();
manager.add_beginrequest(onbeginrequest);
manager.add_endrequest(onendrequest)
}
var lcpostbackelementid;
function onbeginrequest(sender, args)
{
lcpostbackelementid = args.get_postbackelement().id.tolowercase();
if (lcpostbackelementid === 'btnadwords')
{
$get('btnadwords').disabled = true;
$get('btnadwords').value='正在提交...';
}
}
function onendrequest(sender, args)
{
if (lcpostbackelementid === \"btnadwords\")
{
$get('btnadwords').disabled = false;
$get('btnadwords').value='确定';
}
}
< /script>
更多内容请参考:http://msdn.microsoft.com/zh-cn/magazine/cc163319.aspx