FileUpload控件工作的第二次点击,但保存文件的发布不是第一次尝试? [英] FileUpload control working on second click but not first attempt of saving posted file?

查看:129
本文介绍了FileUpload控件工作的第二次点击,但保存文件的发布不是第一次尝试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<一个href=\"http://stackoverflow.com/questions/11559762/fileupload-control-not-working-outside-ajax-update-panel-but-works-inside-wi/11560109#11560109\">My问

我设法回答自己,但相同的功能集,还有另一个问题。出于某种原因,发布文件的保存活动的第一回发命中01'对象未设置为一个对象错误的实例,但对上传的文件,并触发我的拯救事件的第二次尝试(转换为byte []的存储为SQL Server的BLOB)它做一切应该做的。

I managed to answer myself, however the same set of functionality has another problem. For some reason the first postback of the save event of the posted file hits the Ol' Object not set to an instance of an object error, but on the second attempt of uploading a file and firing my save event (converts to byte[] an stored as SQL Server BLOB) it does everything is supposed to do.

<一个href=\"http://stackoverflow.com/questions/8388340/fileupload-updatepanel-does-not-work-on-first-click\">Same问题就在这里

有是使用AJAX AsyncUpload控制然而我是去除病因,而不是处理问题的坚定信仰的一个很好的建议。我会继续下降到最好的我的asp.net等的理解这条路线。

There is a good suggestion of using the AJAX AsyncUpload control however I am a firm believer of removing the cause and not treating the problem. I will continue down this route to best my understanding of asp.net etc.

会不会有你们当中一个wizrd,可以帮助我找出为什么我得到对象参考未设置为obj的出师表第一次回发错误,但在第二个它工作正常。内容页都有它包装内容页在一个更新面板母版页。不是我决定的做到这一点。酒店还设有回发触发器针对我保存事件的更新面板。

Would there be a wizrd amongst you that could help me identify why I get "object ref not set to inst of obj" error on first postback but on second it works fine. Content page has a master page which wraps content page in an update panel. Not my decision to do this. There is also an update panel with postback triggers targeting my save event.

你有什么想法的人吗?

推荐答案

问题(如这里看到HTTP://论坛.asp.net / T / 1060363.aspx )似乎是当您使用周围的面板上的可见性属性(如看来你是从链接的问题)。

The problem (as seen here http://forums.asp.net/t/1060363.aspx) seems to be when you use the visibility property on the surrounding panel (as it seems you are from the linked question).

建议的解决方法是使用CSS的可视性代替使用,使其不可见 -

The suggested workaround is to use CSS visibility instead so use this to make it invisible -

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

从线程对此的解释是

The explanation for this from the thread is

如果你的容器被设置为不可见,上载控制实际上不呈现为HTML,导致窗体的ENCTYPE不被设置为ENCTYPE =的multipart / form-data的,导致文件上传控件不张贴选定文件回服务器。解决方法是确保FileUpload控件呈现为HTML(由它的样式设置为显示:在没有代替可见= false)或通过手动设置ENCTYPE

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

所以,另一个解决办法是改变你的表单标签这个

So another workaround would be to alter your form tag to this

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

我觉得那些中的任何一个应该解决您的问题。

I think either one of those should solve your problem.

这篇关于FileUpload控件工作的第二次点击,但保存文件的发布不是第一次尝试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆