问题
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