I have created a composite control for a file upload input (using an HtmlInputFile control). My problema is that everything works fine until I try to save the file using HtmlInputFile's "SaveAs" in my page's code behind. Whenever I press the button for uploading the file, I get a "object not set to an instance bla bla bla". However if I pause execution right before the SaveAs (with a break point) and then got step by step (F10), all of the composite properties have the corresponding data and I can effectively upload the file.
I am quite sure this has to do with page and control lifecycle, but everything I have read so far has led me no where. Can anyone please shed some light as to how I can force the composite control to load/render before I execute the code behind Click event?
The code behind that triggers the SaveAs is pretty straight forward:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
fup.xmsPostedFile.SaveAs(Server.MapPath(String.Format("~/memberpages/{0}", fup.xmsFileName)))
End Sub
The fup.xmsPostedFile
property only references the _inputControl.PostedFile
property. Same with fup.xmsFileName
.
any help will be greatly appreciated. Thanks in advanced.