简体   繁体   English

当按钮执行代码在更新面板之外时,如何使用更新面板内部的更新进度

[英]How to use update progress inside update panel, when the button executing code is outside update panel

I have a update panel, and a update progress inside it. 我有一个更新面板,里面有更新进度。 I have moved the button outside update panel because, response.write was not working when I had the button inside the update panel. 我将按钮移到了更新面板之外,因为当我将按钮放在更新面板中时,response.write无法正常工作。 Now after moving the button outside the response.write is working but update progress is not. 现在,将按钮移到response.write外部之后,更新正常。 How can I make it to work when I have the button outside. 外面有按钮时,如何使它工作。

 <asp:UpdateProgress ID="UpdateProgress2" runat="server">     
 <ProgressTemplate>      
  <div style="width: 338px; position: relative; top: -420px; left: 80px" class="">          <b>Please Wait...</b>        
    <img runat="server" id="ajaxLoader" style="background-color: White; width: 338px;"                                 src="styles/images/loadImage.gif" alt="loading" />     
    </div>          </ProgressTemplate>         </asp:UpdateProgress>            
      </ContentTemplate>     </asp:UpdatePanel>     
      <asp:Button ID="btn_upload"  runat="server" Text="Upload"                             OnClick="upload_Click" /> 

Use trigger for your update panel 将触发器用于更新面板

<asp:UpdatePanel>

.... content ... 

    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btn_upload" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>

1.) Response.Write does not work inside UpdatePanel by design (see why here: https://stackoverflow.com/a/3878111/1288619 ) - and by default UpdatePanel is automatically triggered by all of its children controls. 1.) Response.Write在设计上无法在UpdatePanel内部工作(请参阅此处的原因: https : //stackoverflow.com/a/3878111/1288619 )-默认情况下, UpdatePanel由其所有子控件自动触发。

2.) When you place the button outside of it, you are triggering full postback and not the UpdatePanel 's partial rendering - so no update progress. 2.)将按钮放置在按钮外部时,将触发完整的回发,而不是UpdatePanel的部分呈现-因此没有更新进度。

When you just register the button as an AsyncPostBackTrigger (where ever it may be) - you get the exact same situation as in the first case. 当您仅将按钮注册为AsyncPostBackTrigger (无论它在哪里)-您会得到与第一种情况完全相同的情况。

If you register the button as a (Full) PostBackTrigger , or set UpdatePanel 's rendering to be conditional and not triggered by its children - then you just get the exact same situation as in the second case. 如果将按钮注册为(Full) PostBackTrigger ,或将UpdatePanel的呈现设置为有条件的,而不是由其子项触发的-那么您将获得与第二种情况完全相同的情况。

So, do as alexsuslin suggests, simply change the text property of some Literal control inside UpdatePanel to what you would put in Response.Write (and set the button's visible property to false if you don't want it shown anymore - but do register it as AsyncPostBackTrigger if moved outside). 因此,按照alexsuslin的建议,只需将UpdatePanel中某些Literal控件的text属性更改为您要在Response.Write放置的内容(然后将按钮的visible属性设置为false,如果您不想再显示它-则请注册作为AsyncPostBackTrigger如果移到外部)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM