SlickUpload
Welcome Guest Search | Active Topics | Log In | Register

Duplicate UploadComplete() Options
goodfella
#1 Posted : Friday, October 23, 2009 7:38:30 PM
Rank: Newbie

Groups: Registered

Joined: 9/28/2009
Posts: 3
Location: Portland, OR

Hello,

The UploadComplete() function seems to be getting called twice and thus is adding records to SQL twice.

protected void SlickUpload1_UploadComplete(object sender, Krystalware.SlickUpload.Controls.UploadStatusEventArgs e)
    {
        uploadPanel.Visible = false;
        resultPanel.Visible = true;

        if (e.UploadedFiles != null && e.UploadedFiles.Count > 0)
        {
            resultsRepeater.DataSource = e.UploadedFiles;
            resultsRepeater.DataBind();

            resultsRepeater.Visible = true;

            //Response.Write(e.UploadedFiles.Count().ToString());
            foreach (UploadedFile file in e.UploadedFiles)
            {
                ....
            }
        }
        else
        {
            resultsRepeater.Visible = false;
        }

       
        TabInit("uploadphotos");
    }

<script type="text/javascript">
       
        function cancelUpload() {
            kw.get("<%=SlickUpload1.ClientID %>").cancel();
        }
        function startUpload() {
            kw.get('<%=SlickUpload1.ClientID %>').submit();
        }
        function fileAdded(file) {
            document.getElementById('<%=btnUpload.ClientID %>').style.display = 'block';
            var extImage = file.getElementById("extImage");

            extImage.src = "FileIcon.ashx?ext=" + file.extension;
        }
        function fileRemoved(file) {
            var SlickUpload1 = kw.get('<%=SlickUpload1.ClientID%>');
            var files = SlickUpload1.get_Files();

            if (files.length == 0) {
                document.getElementById('<%=btnUpload.ClientID %>').style.display = 'none';
            }
        }
    </script>

<asp:Panel ID="uploadPanel" runat="server">
                                                <kw:SlickUpload ID="SlickUpload1" runat="server" AutoUploadOnPostBack="false" ShowDuringUploadElements="cancelButton"
                                                    HideDuringUploadElements="uploadButton" OnClientFileAdded="fileAdded" OnUploadComplete="SlickUpload1_UploadComplete"
                                                    OnClientFileRemoved="fileRemoved" >
                                                    <DownlevelSelectorTemplate>
                                                        <input type="file" />
                                                    </DownlevelSelectorTemplate>
                                                    <UplevelSelectorTemplate>
                                                        <input type="button" value="Add File" />
                                                    </UplevelSelectorTemplate>
                                                    <FileTemplate>
                                                        <div class="fileItem">
                                                        <kw:FileListRemoveLink ID="FileListRemoveLink1" runat="server" CssClass="removeLink">
                                                        <img width="20" height="20" style="vertical-align:middle" src="<%=ResolveUrl("~/images/delete.png") %>" /> remove
                                                        </kw:FileListRemoveLink>
                                                        <img id="extImage" width="32" height="32" class="icon" />
                                                        <kw:FileListFileName ID="FileListFileName1" runat="server" />
                                                        <kw:FileListValidationMessage ID="FileListValidationMessage1" runat="server" ForeColor="Red" />
                                                        </div>
                                                    </FileTemplate>
                                                    <ProgressTemplate>
                                                        <table width="100%">
                                                            <tr>
                                                                <td>
                                                                    Uploading
                                                                    <kw:UploadProgressElement ID="UploadProgressElement1" runat="server" Element="FileCountText">
                                                                    </kw:UploadProgressElement>
                                                                    ,
                                                                    <kw:UploadProgressElement ID="UploadProgressElement2" runat="server" Element="ContentLengthText">
                                                                        (calculating)</kw:UploadProgressElement>
                                                                    .
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    Currently uploading:
                                                                    <kw:UploadProgressElement ID="UploadProgressElement3" runat="server" Element="CurrentFileName">
                                                                    </kw:UploadProgressElement>
                                                                    , file
                                                                    <kw:UploadProgressElement ID="UploadProgressElement4" runat="server" Element="CurrentFileIndex">
                                                                        &nbsp;</kw:UploadProgressElement>
                                                                    of
                                                                    <kw:UploadProgressElement ID="UploadProgressElement5" runat="server" Element="FileCount">
                                                                    </kw:UploadProgressElement>
                                                                    .
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    Speed:
                                                                    <kw:UploadProgressElement ID="UploadProgressElement6" runat="server" Element="SpeedText">
                                                                        (calculating)</kw:UploadProgressElement>
                                                                    .
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    About
                                                                    <kw:UploadProgressElement ID="UploadProgressElement7" runat="server" Element="TimeRemainingText">
                                                                        (calculating)</kw:UploadProgressElement>
                                                                    remaining.
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    <div style="border: 1px solid #008800; height: 1.5em; position: relative">
                                                                        <kw:UploadProgressBarElement ID="UploadProgressBarElement1" runat="server" Style="background-color: #00ee00;
                                                                            width: 0; height: 1.5em">
                                                                        </kw:UploadProgressBarElement>
                                                                        <div style="text-align: center; position: absolute; top: .15em; width: 100%">
                                                                            <kw:UploadProgressElement ID="UploadProgressElement8" runat="server" Element="PercentCompleteText">
                                                                                (calculating)</kw:UploadProgressElement>
                                                                        </div>
                                                                    </div>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </ProgressTemplate>
                                                </kw:SlickUpload>
                                                <p>
                                                    <asp:Button ID="btnUpload" runat="server" Text="Upload" CssClass="uploadButton" OnClientClick="startUpload();return false;" />
                                                    <a href="javascript:kw.get('<%=SlickUpload1.ClientID %>').cancel()" id="cancelButton"
                                                        style="display: none">Cancel</a>
                                                </p>
                                            </asp:Panel>
                                            <asp:Panel ID="resultPanel" runat="server" Visible="false">
                                                <h2>
                                                    Upload Results</h2>
                                                <% if (SlickUpload1.UploadStatus != null)
                                                   { %>
                                                <p>
                                                    Result:
                                                    <%=SlickUpload1.UploadStatus.State%>
                                                    <%if (!(SlickUpload1.UploadStatus.State == UploadState.Complete || SlickUpload1.UploadStatus.State == UploadState.PostProcessingComplete))
                                                      { %>
                                                    <br />
                                                    Reason:
                                                    <%=SlickUpload1.UploadStatus.Reason%>
                                                    <% } %>
                                                    <br />
                                                    Files Uploaded:
                                                    <%=SlickUpload1.UploadedFiles != null ? SlickUpload1.UploadedFiles.Count.ToString() : "N/A"%></p>
                                                <asp:Repeater ID="resultsRepeater" runat="server">
                                                    <HeaderTemplate>
                                                        <table class="results" width="99%" cellpadding="4" cellspacing="0">
                                                            <thead>
                                                                <tr>
                                                                    <th align="left">
                                                                        Name
                                                                    </th>
                                                                    <th align="left">
                                                                        Mime Type
                                                                    </th>
                                                                    <th align="left">
                                                                        Length (bytes)
                                                                    </th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                    </HeaderTemplate>
                                                    <ItemTemplate>
                                                        <tr>
                                                            <td>
                                                                <%#((UploadedFile)Container.DataItem).ClientName %>
                                                            </td>
                                                            <td>
                                                                <%#((UploadedFile)Container.DataItem).ContentType %>
                                                            </td>
                                                            <td>
                                                                <%#((UploadedFile)Container.DataItem).ContentLength %>
                                                            </td>
                                                        </tr>
                                                    </ItemTemplate>
                                                    <FooterTemplate>
                                                        </tbody> </table>
                                                    </FooterTemplate>
                                                </asp:Repeater>
                                                <% } %>
                                                <p>
                                                    <asp:Button ID="newUploadButton" runat="server" Text="New Upload" OnClick="newUploadButton_Click" /></p>
                                            </asp:Panel>

Axosoft
#2 Posted : Friday, October 23, 2009 8:30:57 PM
Rank: Administration


Groups: Administrators

Joined: 7/7/2005
Posts: 1,586
Location: Scottsdale, AZ

Duplicate event firing usually happens because the events are wired up twice. I see the event wired up in the markup (OnUploadComplete="SlickUpload1_UploadComplete"). Do you have AutoEventWireup=true set in the page declaration or web.config? Or are you wiring up the event in the codebehind?

If not, send the .aspx, codebehind, and web.config to chrish at krystalware dot com and I'll have a look.

goodfella
#3 Posted : Monday, October 26, 2009 11:37:10 AM
Rank: Newbie

Groups: Registered

Joined: 9/28/2009
Posts: 3
Location: Portland, OR

Thanks Chris for your reply!

Although I did have AutoEventWireup=true set in the page declaration, after removing it, I'm still let with the same issue. I could find the event wired anywhere else, so I've sent you the aspx, codebehind and web.config file via email.

Thanks again for your help!

ayazaslam
#4 Posted : Wednesday, November 04, 2009 2:02:57 AM
Rank: Newbie

Groups: Registered

Joined: 9/27/2009
Posts: 5
Location: Pakistan

Hello

I am having the same issue. Has anyone found a fix for this? I have the event wired up only in the mark up and page's AutoEventWireup is set to true.

Ayaz

Axosoft
#5 Posted : Wednesday, November 04, 2009 9:44:16 AM
Rank: Administration


Groups: Administrators

Joined: 7/7/2005
Posts: 1,586
Location: Scottsdale, AZ

If you have AutoEventWireup="true", try removing the manual wireup in the page markup. If that doesn't work, send your .aspx, codebehind, and web.config to chrish at krystalware dot com and I'll take a look.

lynnc
#6 Posted : Thursday, November 19, 2009 11:52:51 AM
Rank: Newbie

Groups: Registered

Joined: 11/16/2009
Posts: 3
Location: York, PA

ChrisHynes wrote:

If you have AutoEventWireup="true", try removing the manual wireup in the page markup. If that doesn't work, send your .aspx, codebehind, and web.config to chrish at krystalware dot com and I'll take a look.

I'm seeing this too, and I am also using a case where I set AutoUploadOnPostBack="false" , and then manually call .submit() on the SlickUpload control to being the upload. Chris, have you managed to duplicate this, and/or have a fix?

One other note, I've tried removing the wireup in the page markup, in which case I lose the event altogether, and (separately) I've tried performing the wireup in the codebehind by adding an event handler in page_load, which gets me back to seeing the event firing twice. 

So, two observations in total:

1) Is there any possibility that AutoUploadOnPostBack being false is causing the auto event wireup to not work?

2) Does calling .submit() manually from the page seem to be related to the event firing twice?

- Lynn

Axosoft
#7 Posted : Friday, November 20, 2009 3:30:22 PM
Rank: Administration


Groups: Administrators

Joined: 7/7/2005
Posts: 1,586
Location: Scottsdale, AZ

Shoot me your .aspx, codebehind, and web.config via email (chrish at krystalware dot com) and I'll take a look.

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.