Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • tc 41 posts 62 karma points
    Jul 04, 2012 @ 16:06
    tc
    0

    Custom DataType: Programmatically insert FileUpload control

    I have created a simple data type to allow me to upload a file. To create this I used the method of creating a standard .net control that inherits IUsercontrolDataEditor.

    I'm now in the process of changing this control to the 3 classes method so that I can make use of prevalues. I have created the 3 classes and am currently epanding the DataEditor control to include all elements of the previous control.

    To start with I have a RenderUploadForm() method that is called as part of the OnInit() method, this does the following:

    base.ContentTemplateContainer.Controls.Add(
        new LiteralControl("<div class='uploader-container' id='new-file'>")
    );
    
    base.ContentTemplateContainer.Controls.Add(
        new LiteralControl("<h4>Add new file: </h4>")
    );
                
    fileUpload = new FileUpload();
    base.ContentTemplateContainer.Controls.Add(fileUpload);
    
    btn_Upload = new Button();
    btn_Upload.Text = "Upload File";
    btn_Upload.Click += new EventHandler(uploadFile);
    base.ContentTemplateContainer.Controls.Add(btn_Upload);
    
    base.ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

     

    The controls are rendered on the page as expected, and I can open the file chooser, select a file and then click upload which calls the uploadFile() method as expected.

    However, for some reason fileUpload.HasFile is false. I have also tried checking HttpContext.Current.Request.Files.Count and that is 0.

    I'm not sure what is going on here.

    Any ideas?

  • tc 41 posts 62 karma points
    Jul 04, 2012 @ 18:38
    tc
    0

    After investigation, the DataEditor class inherits UpdatePanel.
    FileUpload controls don't play nice with the UpdatePanel! 

Please Sign in or register to post replies

Write your reply to:

Draft