gpt4 book ai didi

c# - 在 ASP.net Ajax 中禁用更新进度按钮

转载 作者:数据小太阳 更新时间:2023-10-29 04:47:49 27 4
gpt4 key购买 nike

您好,我正在通过 asp.net Ajax 加载大量数据,在 GridView 中单击按钮时显示更新 prgress 上的加载消息...在更新进度时间我必须禁用我的 BtnLoadReport 按钮。

<td>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
<asp:UpdateProgress ID="updProgress"
AssociatedUpdatePanelID="UpdatePanel1"
runat="server" oninit="updProgress_Init" onprerender="updProgress_PreRender">
<ProgressTemplate>
<span style="color:green; font-style:italic;">Loading, please wait...</span>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<div id="DemoId">
<asp:Button ID="BtnLoadReport" runat="server" onclick="BtnLoadReport_Click"
Text="LoadReport" Width="176px" ClientIDMode="Static" OnClientClick="return clickOnLoadReport();" />
</div>
<asp:GridView ID="GridView1" runat="server" Height="170px"
onselectedindexchanged="GridView1_SelectedIndexChanged" Width="438px">
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="BtnLoadReport" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
</table>

禁用按钮的脚本

          <script type="text/javascript">
var updateProgress = null;
function clickOnLoadReport() {
// This will disable all the children of the div
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (prm.get_isInAsyncPostBack()==false) {
var nodes = document.getElementById("DemoId").getElementsByTagName('*');
for (var i = 0; i < nodes.length; i++) {

nodes[i].disabled = true;
// nodes[i].off("click");
}
}
}
</script>

但它不会长时间禁用我的按钮,它只会禁用几秒钟

  protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(this.BtnLoadReport);
}

protected void BtnLoadReport_Click(object sender, EventArgs e)
{
// System.Threading.Thread.Sleep(3000);

UpdatePanel1.Update();
DataSet dataSet = new DataSet();
dataSet.ReadXml(@"C\Data.Xml");
GridView1.DataSource = dataSet.Tables[0];
GridView1.DataBind();

}

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{

}

protected void updProgress_Init(object sender, EventArgs e)
{
BtnLoadReport.Enable = false;
}

protected void updProgress_PreRender(object sender, EventArgs e)
{
BtnLoadReport.Enable
= true;
}

上面的事情我试图禁用我的按钮 BtnLoadReport on Update progress 仍然无法正常工作提前致谢

最佳答案

function clickOnLoadReport() {
var requestManager = Sys.WebForms.PageRequestManager.getInstance();
requestManager.add_initializeRequest(CancelPostbackForSubsequentSubmitClicks);

function CancelPostbackForSubsequentSubmitClicks(sender, args) {
if (requestManager.get_isInAsyncPostBack() &
args.get_postBackElement().id == 'BtnLoadReport') {
args.set_cancel(true);
document.getElementById("BtnLoadReport").setAttribute("disabled", "disabled");
//alert('A previous request is still in progress that was issued on clicking ' + args.get_postBackElement().id);
}
}
}

我修改了我的 javascript 函数,它解决了我的问题

关于c# - 在 ASP.net Ajax 中禁用更新进度按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24821649/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com