Search code examples
asp.netc#-4.0jquerypartial-page-refreshupdatepanel

How to call UpdatePanel1.Update() method from another page in ASP.NET


I have Default.aspx with several controls along with Uploadify Image upload control and i am call another file UploadImages.aspx File to upload image using jQuery, I upload images using general C# code and save image details in the database also.

HTML Code on Default.aspx PAGE

<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="False"  UpdateMode="Conditional">
   <ContentTemplate>                                 
        <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" RepeatDirection="Horizontal" >
            <ItemTemplate>
                <br /><img src='http://test.kashmirsouq.com/ImageUploads/<%# Eval("ImageID") %>' width="100px" height="100px"   vspace="2" hspace="2" border="1" />
                <br /><asp:LinkButton ID="lnkBtnDeleteImage" CommandArgument='<%# Eval("sno") %>' CommandName="Delete" runat="server">
         Delete</asp:LinkButton>
        <br />
            </ItemTemplate>
        </asp:DataList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:SQLConnectionString %>" 
            SelectCommand="SELECT [sno], [ImageID] FROM [User_Images]">
        </asp:SqlDataSource>
 </ContentTemplate>
</asp:UpdatePanel> 

I want to use UpdatePanel1.Update() method To refresh the UpdatePanel1, But i dont know how to register updatePanel1 control in UploadImage.aspx page.

Please help me out with this My basic object is to show the image once it is upload without refreshing the page

Example of page on link removed as i got it working for security reason


Solution

  • Try to use uploadify's onAllComplete event to refresh your update panel from client-side code. For that purpose add onto the page button, add AsyncPostbackHandler for this button to updatepanel's triggers collection and fire click on this button programmatically in uploadify onAllComplete event handler:

    $('#fuFiles').uploadify({
        onAllComplete: function (event, data) { $("#<%= HiddenButton.ClientID %>").click(); return true; },
        uploader: 'Scripts/uploadify.swf',
        script: 'FileUploads.aspx',
        cancelImg: 'Scripts/cancel.png',
        auto: 'true',
        multi: 'true',
        buttonText: 'Browse...',
        queueSizeLimit: 5,
        simUploadLimit: 2
    });
    
    
    <asp:Button runat="server" ID="HiddenButton" Style="display: none;" />
    
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="HiddenButton" />
                </Triggers>