Imagebutton does not fire in UpdatePanel

走远了吗. 提交于 2020-01-03 06:01:06

问题


I am trying to show a progress image when I click an Imagebutton inside updatepanel. On button click c# code should run as well as show the update progress image. With this code, it runs the c# code but doesnt show the progress image, if i remove the postbacktrigger, then it shows the progress image but the c# doesnt run. Any idea how can I fix it ?

<div id="scriptmanager">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true">

        <ContentTemplate>
         <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/SurveyImages/clean.jpg" 
                                     onclick="cmd_clean_emergency_Click"  


                                style="-webkit-appearance:push-button; border-radius:5px; border: 4px solid #E9A732" Enabled="False" 
                                     />
        </ContentTemplate>
        <Triggers>
        <asp:PostBackTrigger ControlID="ImageButton1"/>
        </Triggers>
        </asp:UpdatePanel>
        <asp:UpdateProgress ID="UpdateProgress1" DisplayAfter="0" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
        <ProgressTemplate>
            <img src="images/ProgressBar1.jpg" />

        </ProgressTemplate>
        </asp:UpdateProgress>
    </div>

回答1:


It was my mistake with AsyncPostBack trigger it works. I forgot to put GridView inside updatepanel tag, so the c# code was actually running, but gridview was not updating because it was not inside the updatepanel tag.




回答2:


The reason AsyncPostBackTrigger isn't working is because it's designed for UI-level execution. http://msdn.microsoft.com/en-us/library/system.web.ui.asyncpostbacktrigger.aspx

Notice in the example, the name of the form input field is directly input to the SqlDataSource's select command.


Doing a progress bar via the update-panel is a nightmare; just imagine the UpdatePanel as a small iframe that refreshes, it's not really that contrived, but terms of functionality and UI, it might as well be.

You are better off investigating a JavaScript method of handling the progress-bar. However, there are some solutions here: http://www.dotnetcurry.com/ShowArticle.aspx?ID=227



来源:https://stackoverflow.com/questions/19105794/imagebutton-does-not-fire-in-updatepanel

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