UpdateProgress Not working when called thru javascript

我与影子孤独终老i 提交于 2019-12-11 12:06:02

问题


When i click the button in the update panel i get to see the update progress but when i try to do this through javascript $("#<%=LinkButton1.ClientID %>").click(); updateprogress is not displayed, but update panel is getting refreshed properly. Any Idea why update progress is not working?

<asp:UpdatePanel runat="server" ID="UpdPnl1" UpdateMode="Conditional" >  
    <ContentTemplate>  
      <asp:Button ID="Button1" runat="server" onclick="Button1_Click"   Text="click"/>
       <asp:PlaceHolder ID="Place1" runat="server"></asp:PlaceHolder>
     </ContentTemplate>
</asp:UpdatePanel>

<asp:UpdateProgress ID="updQuoteProgress" runat="server"  AssociatedUpdatePanelID="UpdPnl1"  DisplayAfter="0">
        <ProgressTemplate>Loading...</ProgressTemplate>    
</asp:UpdateProgress>

    <script type="text/javascript">    
        $(document).ready(function () {
            $("#<%=Button1.ClientID %>").click();
        })  
    </script>

回答1:


This is because Sys.Application loaded event occurs after a page's DOM fully loaded. When your script executed the client-side objects responsible for showing UpdateProgress on partial postback not yet initialized. Try this script instead (place it below the ScriptManager control or just at the page's end):

<script type="text/javascript">
     Sys.Application.add_load(function () { $("#<%= Button1.ClientID %>").click(); });
</script>

You also can delay your script execution with script below:

$(function () {
     setTimeout('$("#<%= Button1.ClientID %>").click();', 10);
});


来源:https://stackoverflow.com/questions/7889099/updateprogress-not-working-when-called-thru-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!