原来地址:
Why my ASP.NET AJAX forms are never submitted twice
避免网页重复提交从ASP时代到现在是一直都在讨论的话题,刚看到这篇文章,说的是在ASP.NET AJAX 程序中如何避免重复提交的方法,觉得非常方便和简洁和大家分享,原理就是在
BeginRequest和
EndRequest阶段做了些操作,让按钮变为"disabled = true;",但条件是必须在页面中拖一个ScriptManager,并引用你编写的相关JS脚本即可.
JS:
function BeginRequest(sender, args)
{
// Find the ID of the UpdatePanel raising the partial postback.
var panelID = sender._postBackSettings.panelID.split("|")[0];
// Using that ID, get a reference to that UpdatePanel's div.
var sendingPanel = document.getElementById(sendingPanelID);
// Get an array of all the input elements in that div.
var inputs = sendingPanel.getElementsByTagName('input');
// Loop through the elements and check each one's type.
// if it's a submit type element, disable it.
for (element in inputs)
if (inputs[element].type == 'submit')
inputs[element].disabled = true;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
function EndRequest(sender, args)
{
// Find the ID of the UpdatePanel raising the partial postback.
var panelID = sender._postBackSettings.panelID.split("|")[0];
// Using that ID, get a reference to that UpdatePanel's div.
var sendingPanel = document.getElementById(sendingPanelID);
// Get an array of all the input elements in that div.
var inputs = sendingPanel.getElementsByTagName('input');
// Loop through the elements and check each one's type.
// if it's a submit type element, disable it.
for (element in inputs)
if (inputs[element].type == 'submit')
inputs[element].disabled = false;
}
效果图: