0

I'm building a website (umbraco based) where the users are able to upload multiple images to their posts. What I have so far is:

<asp:TextBox MaxLength="1" Width="29px" runat="server" ID="txtImageAmount" />&nbsp;
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
       <asp:Button ID="btnSubmitImageAmount" runat="server" Text="Vis upload felter" 
            onclick="btnSubmitImageAmount_Click" />

       <asp:Label Visible="false" ID="lblImageAmountError" ForeColor="Red" runat="server" Text="Maks 3 billeder"></asp:Label>  
       <asp:Panel ID="pnlUploadControls" Visible="false" runat="server"></asp:Panel>
    </ContentTemplate>
</asp:UpdatePanel>  

So the user is able to choose the amount of fileupload boxes (max 3 though) on the site.

My C# looks like this:

protected void btnSubmitImageAmount_Click(object sender, EventArgs e)
{
    int amountOfControls = Convert.ToInt32(txtImageAmount.Text);
    if (amountOfControls <= 3)
    {
        for(int i = 0; i < amountOfControls; i++)
        {
            FileUpload fUl = new FileUpload();
            fUl.ID = i.ToString();
            fUl.Width = 300;
            Label lblLinebreak = new Label();
            lblLinebreak.Text = "<br />";
            pnlUploadControls.Controls.Add(fUl);
            pnlUploadControls.Controls.Add(lblLinebreak);
            pnlUploadControls.Visible = true;
        }
    }
    else
    {
        lblImageAmountError.Visible = true;
    }
}

So basically I'm adding a new FileUpload control to the Panel depending on how many the user wants.

Now, in my Save button I have the following code:

List<Media> images = new List<Media>();

    foreach (FileUpload fUl in pnlUploadControls.Controls)
    {
        Media m = UmbracoSave(fUl);
        if (m != null)
        {
            images.Add(m);
        }       
    }

    if (images.Count > 0)
    {
        RelationType ad2media = RelationType.GetByAlias("ad2media");
        foreach (Media img in images)
        {
            Relation.MakeNew(adDoc.Id, img.Id, ad2media, adDoc.Text + " is related to " + img.Text);
        }
    }

I have tried to check if the amount of controls in the panel is equal to 0 and it seems it is.. The weird thing is, if I check if the Media item returned from the UmbracoSave method is null, it isn't.

Also, it says that the List (images) count is 0..

Can anyone shed some light on this? :-)

Any help is greatly appreciated!

All the best,

Bo

1 Answer 1

3

You can't put a standard FileUpload control in an UpdatePanel. It just doesn't work. Look at an AJAX compatible file upload component.

Sign up to request clarification or add additional context in comments.

4 Comments

Yep. Should be able to use Gecko Uploadify for Umbraco: our.umbraco.org/projects/website-utilities/gecko-uploadify
Hi ck, thanks for your answer :) I thought you could place just about any asp.net control inside an UpdatePanel, but oh well.. I tried to delete the updatepanel but on my Save Button click event it still tells me that my panel (pnlUploadControls) Controls collection is 0 :(
@sebastiaan: Thanks mate, although this is due to happen on the site itself and not in the Umbraco backend administration..
@bo it should work as a standard usercontrol as well, but I haven't tried it, have a look in the project's forum and ask there if you can't find anything on the subject.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.