gpt4 book ai didi

c# - FileUpload 控件在第二次单击时起作用,但不是第一次尝试保存发布的文件?

转载 作者:太空狗 更新时间:2023-10-29 22:08:21 25 4
gpt4 key购买 nike

My Question

我设法回答了自己,但是同一组功能还有另一个问题。由于某种原因,已发布文件的保存事件的第一次回发命中了 Ol' Object not set to an instance of an object 错误,但是在第二次尝试上传文件并触发我的保存事件(转换为 byte[] 和存储为 SQL Server BLOB)它做所有应该做的事情。

Same problem here

有一个使用 AJAX AsyncUpload 控件的好建议,但我坚信应该消除原因而不是解决问题。我将继续沿着这条路走下去,以最好地理解 asp.net 等。

你们中间有没有一个向导可以帮助我确定为什么我在第一次回发时收到“对象引用未设置为对象的实例”错误,但在第二次回发时它工作正常。内容页面有一个母版页,它将内容页面包装在更新面板中。不是我决定这样做。还有一个更新面板,其中包含针对我的保存事件的回发触发器。

大家有什么想法?

最佳答案

问题(如此处所示 http://forums.asp.net/t/1060363.aspx )似乎是当您在周围面板上使用可见性属性时(因为您似乎来自链接问题)。

建议的解决方法是改用 CSS 可见性,因此使用它可以使其不可见 -

<asp:Panel ID="pnlUpload" runat="server" class="workerDetailsPanelLeft" style="display:none">

线程对此的解释是

If your container is set to invisible, the upload control is not actually rendered as HTML, causing the form's enctype not to be set to enctype="multipart/form-data", causing the file upload control not to post the selected file back to the server. The workaround is either to make sure the FileUpload control is rendered to HTML (by setting its style to display:none in stead of Visible=false), or by manually setting the enctype

所以另一种解决方法是将您的表单标签更改为此

<form id="form1" enctype="multipart/form-data" runat="server">

我认为其中任何一个都可以解决您的问题。

关于c# - FileUpload 控件在第二次单击时起作用,但不是第一次尝试保存发布的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11575716/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com