C# 在asp.net中如何在初始页面加载时触发UpdateProgress

C# 在asp.net中如何在初始页面加载时触发UpdateProgress,c#,javascript,asp.net,asp.net-ajax,updatepanel,C#,Javascript,Asp.net,Asp.net Ajax,Updatepanel,问题: 为什么我的UpdateProgress在初始页面加载期间不显示,但在后续的回发中通过单击按钮显示 我唯一能让它工作的方法就是用定时器,我不喜欢它。还有别的办法吗 有人能解释为什么doSearch导致updateprogress通过单击按钮而不是通过docoment ready在页面加载上工作吗 代码: Js处理程序: <script> $(document).ready(doSearch); function doSearch() { $('

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

我唯一能让它工作的方法就是用定时器,我不喜欢它。还有别的办法吗

有人能解释为什么doSearch导致updateprogress通过单击按钮而不是通过docoment ready在页面加载上工作吗

代码:

Js处理程序:

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

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

在某种程度上,jQuery库可能会干扰MS AJAX库。尝试强制它显示:

<script>
    $(document).ready(function() {
         $('#<%= UpdateProgress1.ClientID %>').show();    
         doSearch();
    });

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

最后我想我找到了:

<%@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>
非常感谢所有的想法。
Aurelio J.Maldonado

感谢您的回复,第一种方法与我目前使用的方法相同,只是在面板加载之前显示了按钮。第二个根本没有加载任何内容,也没有单击按钮。请您解释一下您更改了什么以及为什么更改?
<script>
    $(document).ready(function() {
         $('#<%= UpdateProgress1.ClientID %>').show();    
         doSearch();
    });

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

    function doSearch() {
        $('#<%= UpdatePanel1Trigger.ClientID %>').click();
        return false;
    }
</script>
<%@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