UploadAttachments loses file info during multiple postbacks (Viewstate is enabled)

Last post 03-15-2012, 2:36 PM by Adam. 9 replies.
Sort Posts: Previous Next
  •  12-21-2011, 5:33 AM 72380

    UploadAttachments loses file info during multiple postbacks (Viewstate is enabled)

    Hi all,
     
    I'm using a trail of the asp.net Ajaxuploader. When I place the UploadAttachments control inside a MultiView control and switch between different views, at some point, the UploadAttachments control looses its viewstate (i think). It displays "(-1Bytes)". Sometimes it takes 2 postbacks, other times 3 to loose viewdata.
     
    I've got viewstate enabled.
     
    Is this normal (by design)? Or am I doing something wrong.
     
    EDIT: Able to reproduce
    It seems that the Uploadattachments control can only handle 1 postback. When I change to View #2 and then back to View #1, all files are still there. If I post to View #2 en then View #3 en than back to View #1, all files are gone.
     
    Filed under:
  •  12-21-2011, 7:11 AM 72386 in reply to 72380

    Re: UploadAttachments loses file info during multiple postbacks (Viewstate is enabled)

    Hi tweek82,
     
    Please add the code below into your page, uploader1 is the uploader control id.
     
      protected override void OnPreRender(EventArgs e)
            {
                base.OnPreRender(e);
                uploader1.Items.ToString();
            }
     
    Regards,
     
    Ken 
  •  03-15-2012, 8:10 AM 73468 in reply to 72386

    Re: UploadAttachments loses file info during multiple postbacks (Viewstate is enabled)

    This doesn't help.
  •  03-15-2012, 9:52 AM 73475 in reply to 73468

    Re: UploadAttachments loses file info during multiple postbacks (Viewstate is enabled)

    Hi thorn,
     
    I created an example with the asp:MultiView control, please try it on your end. Does it work?
     
    <%@ Page Language="C#" %>
    <%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>
    <html>
    <head>
        <script runat="server">
            protected override void OnPreRender(EventArgs e)
            {
                base.OnPreRender(e);
                uploader1.Items.ToString();
            }
            protected void NextButton_Command(object sender, EventArgs e)
            {
                if (DevPollMultiView.ActiveViewIndex > -1 & DevPollMultiView.ActiveViewIndex < 2)
                {
                    DevPollMultiView.ActiveViewIndex += 1;
                }
            }
            protected void BackButton_Command(object sender, EventArgs e)
            {
                if (DevPollMultiView.ActiveViewIndex > 0 & DevPollMultiView.ActiveViewIndex <= 2)
                {
                    DevPollMultiView.ActiveViewIndex -= 1;
                }
                else if (DevPollMultiView.ActiveViewIndex == 2)
                {
                    DevPollMultiView.ActiveViewIndex = 0;
                }
                else
                {
                    throw new Exception("An error occurred.");
                }
            }
        </script>
    </head>
    <body>
        <form id="Form1" runat="Server">
        <asp:Panel ID="Page1ViewPanel" Width="330px" Height="150px" HorizontalAlign="Left"
            runat="Server">
            <asp:MultiView ID="DevPollMultiView" ActiveViewIndex="0" runat="Server">
                <asp:View ID="Page1" runat="Server">
                    step1
                    <CuteWebUI:UploadAttachments ID="uploader1" runat="server">
                    </CuteWebUI:UploadAttachments>
                    <asp:Button ID="Page1Next" Text="Next" OnClick="NextButton_Command" runat="Server">
                    </asp:Button>
                </asp:View>
                <asp:View ID="Page2" runat="Server">
                    step2
                    <asp:Button ID="Page2Back" Text="Previous" OnClick="BackButton_Command" runat="Server">
                    </asp:Button>
                    <asp:Button ID="Page2Next" Text="Next" OnClick="NextButton_Command" runat="Server">
                    </asp:Button>
                </asp:View>
                <asp:View ID="Page3" runat="Server">
                    step3
                    <asp:Button ID="Page3Back" Text="Previous" OnClick="BackButton_Command" runat="Server">
                    </asp:Button>
                </asp:View>
            </asp:MultiView>
        </asp:Panel>
        </form>
    </body>
    </html>
     
    Regards,
     
    Ken 
  •  03-15-2012, 10:33 AM 73477 in reply to 73475

    Re: UploadAttachments loses file info during multiple postbacks (Viewstate is enabled)

    This example works for me, but the bug still exists in my more complex page .
    BTW, I've discovered that uploaded files in the temp dir are deleted after the first postback.
    What can be the reason behind this? 
  •  03-15-2012, 11:46 AM 73478 in reply to 73477

    Re: UploadAttachments loses file info during multiple postbacks (Viewstate is enabled)

    How does the control decide that it's time for files to be deleted?
  •  03-15-2012, 11:57 AM 73479 in reply to 73478

    Re: UploadAttachments loses file info during multiple postbacks (Viewstate is enabled)

    Hi thorn,
     
    The temp files will be deleted after 8 hours.
     
    About the -1 problem. Can you create an example page which can reproduce this issue and post here? So we can check it for you.
     
    Is not easy to find out the problem if I can not reproduce this issue on my end.
     
    Regards,
     
    Ken 
  •  03-15-2012, 12:28 PM 73481 in reply to 73479

    Re: UploadAttachments loses file info during multiple postbacks (Viewstate is enabled)

    Ken, I'm sorry, but I can't isolate the problem. It's stably reproduced only deep inside my control tree. For example, when I move the uploader control to the parent of its current containing user control the bug disappears. But I need the uploader exactly in that place where I have it.
     
    IMHO the deletion of temporary files is the key for this problem. The uploader is placed inside an updatepanel. And files are not deleted after partial postbacks caused by uploading of additional files. But they are stably deleted after the first full postback. Why could it be like this? Could you tell me any possible reasons?
     
    Thank you for your quick response.
     
    Georgii
  •  03-15-2012, 12:45 PM 73482 in reply to 73481

    Re: UploadAttachments loses file info during multiple postbacks (Viewstate is enabled)

    Ooops! It was my fault. It was my code that deleted files. I'm sorry!
  •  03-15-2012, 2:36 PM 73484 in reply to 73482

    Re: UploadAttachments loses file info during multiple postbacks (Viewstate is enabled)

View as RSS news feed in XML