DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> AJAX入門 >> AJAX基礎知識 >> ajax 防止用戶反復提交的2種解決方案
ajax 防止用戶反復提交的2種解決方案
編輯:AJAX基礎知識     
可在服務器端加載方法:
復制代碼 代碼如下:
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
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved