As the title of the thread states, I have a file upload control inside an update panel and added a postbacktrigger to activate a full post back when the submit button is pressed but everytime I try and upload a file the HasFile property never equals true even though I know I chose a file with the file upload control. Am I missing something essential? Here is a snippet of the code..
1<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true">2 <ContentTemplate>34 ...5 ...6 ...78 </ContentTemplate>910 <Triggers>11 <asp:PostBackTrigger ControlID="PropertyValueSubmitButton" />12 </Triggers>1314</asp:UpdatePanel>
Hi There,
As what i can see, your code seem to be alright.
I even run a test base on your scenaria.
<asp:UpdatePanelID="UpdatePanel1"runat="server"ChildrenAsTriggers="true"><ContentTemplate>
<asp:FileUploadID="FileUpload1"runat="server"/>
<asp:ButtonID="btnPostBack"runat="server"Text="My PostBack Button"OnClick="btnPostBack_Click"/>
</ContentTemplate>
<Triggers>
<asp:PostBackTriggerControlID="btnPostBack"/>
</Triggers></asp:UpdatePanel>
In code behind, i set a break point and test the value is true when i select a file and post it by click on the button
protectedvoid btnPostBack_Click(object sender,EventArgs e){
Boolean b = FileUpload1.HasFile;}
Hi kbeeveer46,
Has your problem been resolved yet? If yes , sharing your work will be greatly appreciated!
Hi did you find a solution to your problem. I experience the same problem.
/Frederik
Hi,
I trying the exakt same thing with an AsynPostBackTrigger and then the FileUpload1.HasFile returns false. Do you know why this is so. What am I doing wrong.
I ran into almost exactly the same problem, although mine was a little more difficult because my File Upload control was in a dynamically loaded User Control and couldn't be moved outside of the Update Panel. I set the PostBackTrigger so that everything inside the userconrol would post back. I ran into the same problem that the .HasFile value was always false/null on the first page load. If I posted the page back with any button, then the upload control would work.
I had another AJAX application that was set up almost identical and it was working fine after setting the postbacktrigger. I started looking for differences, and in my default.aspx in the working app I found the following directive on the Form statement:
enctype="multipart/form-data"
Looks like this:
<formid="Form1"method="post"enctype="multipart/form-data"runat="server">
I'm not sure why I ever put it there, and I read on another post where this shouldn't matter, but guess what... I put that in my default.aspx and tried the non-working app again, and viola. Working like a charm.
I never did find a solution but I will definitely try out what hartmacw has said.
EDIT: hartmacw's solution worked perfectly. Thanks.
No comments:
Post a Comment