英文:
Asp.net/C# : asp:FileUpload control has no PostedFiles on codebehind (button click) although the file is appearing on page
问题
I'm trying to access an asp:fileupload from codebehind on a button click. Unfortunately, the control has no files although the filename appears on the page.
The button is inside an updatepanel (I don't want it to affect the page).
<asp:UpdatePanel ID="UpdatePanel18" runat="server">
<ContentTemplate>
<asp:Button runat="server" ID="saveDraftButton" Text=" حفظ بيانات نموذج الإضافة مؤقتاً " OnClick="saveDraftButton_Click" CssClass="btn btn-outline btn-primary btn-lg btn-block" />
</ContentTemplate>
</asp:UpdatePanel>
The fileuploads are outside the update panel.
<asp:FileUpload ID="FileUpload1" AllowMultiple="true" runat="server" Visible="false" CssClass="form-control" />
Could you please help me? I'm stuck here for a while.
英文:
I'm trying to access an asp:fileupload from codebehind on a button click. Unfourtionatly the control has no files although the filename appear on page.
The button is inside an updatepanel ( i don't want it to affect the page ).
<asp:UpdatePanel ID="UpdatePanel18" runat="server">
<ContentTemplate>
<asp:Button runat="server" ID="saveDraftButton" Text=" حفظ بيانات نموذج الإضافة مؤقتاً " OnClick="saveDraftButton_Click" CssClass="btn btn-outline btn-primary btn-lg btn-block" />
</ContentTemplate>
</asp:UpdatePanel>
the fileuploads are outside the update panel
<asp:FileUpload ID="FileUpload1" AllowMultiple="true" runat="server" Visible="false" CssClass="form-control" />
Could you please help me I'm stuck here for awhile.
答案1
得分: 1
以下是翻译好的内容:
如果文件上传和控件位于更新面板之外,那么当您单击按钮时,只有更新面板会被发送到服务器。这就是更新面板的整个理念(它只会回传面板内部的内容,而将页面的其余部分留在原地)。
这表明您可能不了解网页和回传的工作原理。您真的需要花时间理解这个概念,否则您无法编写任何基于Web的软件。
不管以上情况如何?
对于更新面板,您只能在包含在更新面板内时使用控件并获取它们的值。只有页面的那部分(在更新面板内部)将被发送到服务器(这是整个概念的一部分 - 您不能触及或使用更新面板之外的控件,例如文本框,或在这种情况下的文件上传控件)。
然而,更糟糕的是,文件上传控件无论如何都无法在更新面板内工作 - 您需要进行完整的页面回传。
有几种解决方案,但其中一种解决方案是采用基于Ajax构建的文件上传控件,因此您可以上传多个文件,而无需进行回传。
有很多选择。我一直在使用Ajax工具包中的AjaxFileUpload。
英文:
Well, if the file uploads and controls are outside of the update panel, then when you click the button, ONLY the UP panel is posted to the server. This is the WHOLE idea of a update panel (it ONLY posts back what's inside of the panel - and leaves the rest of the page behind).
This suggests that you don't grasp how a web page and post-back works. You REALLY need to spend time grasping this concept, else you can't really write any web based software.
Regardless of above?
For an update panel, You can only EVER use controls and get their values when included in the update panel. Only that part of the page (inside the Update panel) will be posted to the server (kind of the whole idea - you can't touch or use controls outside of the update panel such as text boxes, or in this case the file up-load control).
However, what is worse, is the FileUpLoad control does NOT work inside of a update panel anyway - you need a full page post-back.
there are several solutions, but one such solution would be to adopt a file up load control built around ajax, and thus you can up-load multiple files, and do so without a post-back.
There are "oh so many" to choose from. I been using the AjaxFileUpLoad from the ajax toolkit.
It looks like this:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论