Reputation: 1607
i am facing strange issue: File upload is not working inside update panel. I know this is common issue, however common solutions are not working here. i.e. I have tried using post-back trigger for upload button.
Code is like:
<asp:UpdatePanel runat="server">
<ContentTemplate>
<div runat="server" id="divAttachments" style="margin-top: 10px;">
<div class="attachment collapsableDiv" onclick="HideShowAttachments();" style="margin-left: auto;
margin-right: auto;">
<img id="imgStatusMain" src="../Images/open.gif" class="showHide rightImage" runat="server" />
Attachments <span class="mandatory">*</span>
</div>
<div id="attachmentDiv" style="margin-left: auto; margin-right: auto;">
<asp:GridView runat="server" ID="gvAttachments" CssClass="innerGrid" EmptyDataText="No attachments added"
DataKeyNames="Id" AutoGenerateColumns="false" OnRowDataBound="gvAttachments_RowDataBound"
OnRowCommand="gvAttachments_RowCommand">
<Columns>
<asp:TemplateField HeaderText="File name">
<ItemTemplate>
<asp:LinkButton
runat="server" ID="gvlblFileName" Text='<%#Eval("FileName") %>' OnClick="gvlblFileName_Click"></asp:LinkButton>
<asp:HiddenField runat="server" ID="hfFileName" Value='<%#Eval("Id") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="lbtnDelete" runat="server" CausesValidation="False" CommandName="remove"
Text="Delete" ToolTip="Click to delete" CommandArgument='<%# DataBinder.Eval(Container, "RowIndex") %>'></asp:LinkButton>
</ItemTemplate>
<ItemStyle CssClass="action" />
</asp:TemplateField>
</Columns>
</asp:GridView>
<span class="label" runat="server" id="spnAttachments" style="margin: 10px 10px 10px 50px;">
Attachments</span>
<asp:FileUpload runat="server" ID="fuAttachements" onchange="UploadFile();" Style="margin: 10px 0px 10px 0px;" /><asp:LinkButton
runat="server" ID="lbUploadFile" OnClick="lbUploadFile_Click"></asp:LinkButton>
</div>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlCategory" EventName="SelectedIndexChanged" />
<asp:PostBackTrigger ControlID="lbUploadFile" />
</Triggers>
</asp:UpdatePanel>
And my cs code is like:
if (string.IsNullOrEmpty(fuAttachements.FileName))
result.AddError("Please give valid file name.");
else
{ //code goes here}
I always get blank file name
Is there any other solution for this?. I can not remove update panel.
I have searched on Google and have checked lots of links, but everywhere same solution is given
Upvotes: 0
Views: 1419
Reputation: 5068
unfortunately the fileupload does not work in an update panel; it never has. it requires a full 'normal' postback. there's no way around it. you have to move it out of the panel.
Upvotes: 1