My question is a simple one to answer I hope.
I am making a simple form with a file upload control that was not used in an AJAX panel at first and for the life of me I cannot work out why my code, which remains unchanged, would not find the contents of the FileUpload control.
<asp:Panel ID="pnlUpload" runat="server" class="workerDetailsPanelLeft" Visible="true">
<h3 class="titleHighlightStyle">Probation Documents</h3><br />
<table cellspacing="0">
<tr>
<td class="standardLabel" valign="top">Current Documents</td>
<td colspan="2">
<asp:ListBox ID="lstDocs" runat="server" Width="200px"></asp:ListBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:ImageButton ID="btnSelect" runat="server" SkinID="selectprobationdoc"/>
</td>
<td class="standardLabel" style ="width:200px">Select documents</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td class="standardLabel">Upload Documents</td>
<td colspan="2">
<asp:FileUpload ID="uplDoc" runat="server" Height="22px" Width="200px"/>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" CausesValidation="False" />
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblUploadError" runat="server" Text="Probation document required" ForeColor="Red" Visible="false"></asp:Label>
</td>
</tr>
</table>
</asp:Panel>
Forgive the formatting I deleted the white space!!
Now when my markup is like this and I call .HasFile() on the FileUpload it returns a null value?
When I add the following
<asp:UpdatePanel ID="ContentPanel" UpdateMode="Conditional" runat="server" ChildrenAsTriggers="true">
<Triggers>
<asp:PostBackTrigger ControlID="btnSave" />
</Triggers>
<ContentTemplate>
*Markup as above*
I can get the contents of the control. I understand that there was an issue with the Ajax update panel with file upload control and the solution is to add a postback trigger, but can anyone see from this markup why it may fail o find the file?
if (this.uplDoc.HasFile)
{
String fileExtension = System.IO.Path.GetExtension(uplDoc.FileName).ToLower();
String validExt = sAllowedExt;
if (validExt.IndexOf("," + fileExtension + ",") != -1)
{
if (this.uplDoc.FileBytes.Length >= 0)
{
return string.Empty;
}
else
{
return "PROC0003"; //Invalid File Size
}
}
else
{
return "PROC0002"; //Invalid file type
}
}
Above is the initial code behind check, this never changed from ading the update Panel.
Can someone help me understand what I missed?
Thanks
It was a simple one to answer,
Master page that hosts the content pages wraps those pages in an update Panel, hence why my code was not getting the contents of the file upload control, it was doing an asynchronous postback and not a full postback.
Thanks anyway @Shai