gpt4 book ai didi

c# - 如何在 ASP.NET 中的初始页面加载时触发 UpdateProgress

转载 作者:行者123 更新时间:2023-11-28 08:28:48 28 4
gpt4 key购买 nike

问题:为什么我的 UpdateProgress 在初始页面加载期间不显示,但在通过按钮单击进行的后续回发中显示?

我成功实现此功能的唯一方法是使用计时器,但我并不热衷于计时器。还有别的办法吗?

有人可以解释为什么 doSearch() 会导致 updateprogress 通过单击按钮来工作,但不能通过文档就绪进行页面加载吗?

代码:

Js 处理程序:

<script>
$(document).ready(doSearch);

function doSearch() {
$('#<%= UpdatePanel1Trigger.ClientID %>').click();
return false;
}
</script>

aspx:

//if i click this button the updateprogress works
//and the panel loads
<asp:Button ID="btnSearch" runat="server" Text="Search" CssClass="form-control"
OnClientClick="return doSearch();" />

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"
OnLoad="UpdatePanel1_Load" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:Button ID="UpdatePanel1Trigger" runat="server"
style="display:none" OnClick="UpdatePanel1Trigger_Click" />
<%--gridview that takes a while to load--%>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server"
AssociatedUpdatePanelID="UpdatePanel1" DisplayAfter="1">
<ProgressTemplate>
<asp:Image ID="imgUpdateProgress1" runat="server"
ImageUrl="~/Images/spinner.gif" AlternateText="Loading ..." ToolTip="Loading ..."/>
</ProgressTemplate>
</asp:UpdateProgress>

隐藏代码:

    protected void UpdatePanel1Trigger_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(m_search))
{
performSearch(); //loads data for gridview in updatepanel
}
}

最佳答案

我想我终于找到了:

<%@Page Language="VB" AutoEventWireup="false"
CodeFile="prueba.aspx.vb" Inherits="Programación_prueba" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>UpdatePanel Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"/>
<asp:UpdateProgress runat="server" ID="PageUpdateProgress">
<ProgressTemplate>
Loading...
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel runat="server" ID="Panel">
<ContentTemplate>
<asp:Button runat="server" ID="UpdateButton" OnClick="UpdateButton_Click" Text="Update"/>
<asp:Timer runat="server" ID="UpdateTimer" Interval="5000" OnTick="UpdateTimer_Tick"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger controlid="UpdateTimer" eventname="Tick"/>
</Triggers>
</asp:UpdatePanel>
</form>
</body>
</html>

这是背后的代码:

Partial Class Programación_prueba
Inherits System.Web.UI.Page

Protected Sub UpdateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpdateButton.Click
System.Threading.Thread.Sleep(3000)
End Sub

Protected Sub UpdateTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpdateTimer.Tick
Me.UpdateButton_Click(Me.UpdateButton, Nothing)
End Sub
End Class

非常感谢您的所有想法。奥雷利奥·J·马尔多纳多

关于c# - 如何在 ASP.NET 中的初始页面加载时触发 UpdateProgress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22098359/

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