Quantcast
Channel: ActiveTopics
Viewing all articles
Browse latest Browse all 72689

Custom DataType: Programmatically insert FileUpload control

$
0
0

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?


Viewing all articles
Browse latest Browse all 72689

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>