2008年7月7日 星期一

防止表單被重複 Submit 送出

方法1.
<body onbeforeunload="oIn=document.getElementsByTagName('INPUT');for(i=0; i<oIn.length; i++){oIn(i).disabled=true};">
PS. 此方法會跟 listview 的 NumericPagerField DataPager 及 BWSLib.DefaultGrid 相衝

方法2.
於網頁上放置ScriptManager,UpdatePanel
將送出按鈕放置於UpdatePanel中
於網頁最後加入下面程式

<script language="javascript">
// Get a reference to the PageRequestManager.
var prm = Sys.WebForms.PageRequestManager.getInstance();

// Using that prm reference, hook _initializeRequest
// and _endRequest, to run our code at the begin and end
// of any async postbacks that occur.
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);

// Executed anytime an async postback occurs.
function InitializeRequest(sender, args)
{
// Get a reference to the element that raised the postback,
// and disables it.
$get(args._postBackElement.id).disabled = true;
}

// Executed when the async postback completes.
function EndRequest(sender, args)
{
// Get a reference to the element that raised the postback
// which is completing, and enable it.
$get(sender._postBackSettings.sourceElement.id).disabled = false;
}
</script>

沒有留言:

input 連結 datalist 用程式控制彈出選項

範例: nextTick(() => document.querySelector('input').showPicker());  ※僅支援現代瀏覽器