gpt4 book ai didi

c# - 带触发器的 UpdateProgress 不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 16:33:05 24 4
gpt4 key购买 nike

我正在尝试将 UpdateProgress 与触发器一起使用(请参阅下面的代码)但是当单击分配为 asyncPostBackTrigger 的按钮时,UpdateProgress 不起作用。如果我删除 AssociatedUpdatePanelID 属性,UpdateProgress 控件将起作用。但是我想配置独立的 UpdateProgress 所以,我需要指定UpdateProgress 控件的 AssociatedUpdatePanelID 属性。

这是应该的行为吗?

NOTE: I do not want to intercept the Sys.WebForms.PageRequestManager instance and manipulate the asyncronous request to manually display and hide the UpdateProgress element. Is there a way to do that?

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="AjaxExtensionsTest._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server">
</asp:ScriptManager>
<h2>
Ajax Extensions Test
</h2>
<asp:UpdatePanel ID="up1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<div id="content">
<asp:TextBox ID="txtDataHora" runat="server"></asp:TextBox>
<asp:UpdateProgress ID="progress1" AssociatedUpdatePanelID="up1" DynamicLayout="true" DisplayAfter="0" runat="server">
<ProgressTemplate>
<div>
<img alt="progress" src="loading.gif" />
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSubmit" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="btnSubmit" Text="Get Current Date/Time" runat="server" onclick="btnSubmit_Click" />
<p>
</p>
</asp:Content>
<script runat="server" language="csharp">

protected void Page_Load(object sender, EventArgs e)
{
ScriptManager1.RegisterAsyncPostBackControl(btnSubmit);
}

protected void btnSubmit_Click(object sender, EventArgs e)
{
txtDataHora.Text = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss");
System.Threading.Thread.Sleep(2000);
}
</script>

最佳答案

如果您需要使用 AsyncPostBackTrigger 和 AssociatedUpdatePanelID,那么您唯一的选择是处理 Sys.WebForms.PageRequestManager 实例上的事件并手动显示和隐藏 UpdateProgress 元素。那里有代码在服务器上运行并注入(inject)必要的 JavaScript,这些 JavaScript 可以封装到控件中,从而使这一切变得非常整洁。

关于c# - 带触发器的 UpdateProgress 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10162138/

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