FileUpload控件不工作“外部”AJAX更新面板的作品,但“内”与​​回传触发? [英] FileUpload Control not working 'Outside' AJAX Update Panel but works 'Inside' with Postback trigger?

查看:80
本文介绍了FileUpload控件不工作“外部”AJAX更新面板的作品,但“内”与​​回传触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是一个简单的回答我的希望。

My question is a simple one to answer I hope.

我想提出一个简单的形式,这不是在AJAX面板在第一,为我的生活中,我想不通,为什么我的code,将保持不变,不会找到的内容使用的文件上传控件的FileUpload控件。

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>
&nbsp;
</td>
<td>
<asp:ImageButton ID="btnSelect" runat="server" SkinID="selectprobationdoc"/>
</td>
<td class="standardLabel" style ="width:200px">Select documents</td>
</tr>
<tr>
<td>
&nbsp;
</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>
&nbsp;
</td>
<td>
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" CausesValidation="False" />
</td>
</tr>
<tr>
<td>
&nbsp;
</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!!

现在,当我的标记是这样的,我叫.HasFile()上的FileUpload它返回一个空值?

Now when my markup is like this and I call .HasFile() on the FileUpload it returns a null value?

当我添加以下

<asp:UpdatePanel ID="ContentPanel" UpdateMode="Conditional" runat="server" ChildrenAsTriggers="true">
<Triggers>
<asp:PostBackTrigger ControlID="btnSave" />
</Triggers>
<ContentTemplate>
  *Markup as above*

我可以得到控制的内容。据我了解,有一个问题与文件上传控制的Ajax更新面板和解决方案是增加一个触发回传,但任何人都可以从这个标记明白为什么它可能会失败o找到该文件?

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        
            }
        }

以上是检查背后的初始code,这从来没有从ading更新面板改变。

Above is the initial code behind check, this never changed from ading the update Panel.

有人可以帮助我理解我错过了吗?

Can someone help me understand what I missed?

感谢

推荐答案

这是一个简单的回答,

这是承载内容页母版页包装的更新面板中的页面,因此为什么我的code没有得到文件上传控件的内容,它是做一个异步回发,而不是一个完整的回发。

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.

不管怎样,谢谢@Shai

Thanks anyway @Shai

这篇关于FileUpload控件不工作“外部”AJAX更新面板的作品,但“内”与​​回传触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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