简体   繁体   English

FileUpload Control无法在“外部” AJAX更新面板中运行,但在具有回发触发器的“内部”中运行吗?

[英]FileUpload Control not working 'Outside' AJAX Update Panel but works 'Inside' with Postback trigger?

My question is a simple one to answer I hope. 我的问题是我希望回答的一个简单问题。

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. 我正在使用一个简单的文件上传控件来制作一个简单的表单,该控件最初并未在AJAX面板中使用,并且对于我一生来说,我无法弄清楚为什么我的代码(保持不变)找不到FileUpload控件的内容。

<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!! 原谅我删除空格的格式化!!

Now when my markup is like this and I call .HasFile() on the FileUpload it returns a null value? 现在,当我的标记是这样,并且我在FileUpload上调用.HasFile()时,它返回空值吗?

When I add the following 当我添加以下内容

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

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? 我了解带有文件上传控件的Ajax更新面板存在问题,解决方案是添加回发触发器,但是谁能从此标记中看到为什么它可能失败或找不到文件?

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

Above is the initial code behind check, this never changed from ading the update Panel. 上面是检查后面的初始代码,此代码从更新面板开始就没有改变。

Can someone help me understand what I missed? 有人可以帮助我了解我错过了什么吗?

Thanks 谢谢

It was a simple one to answer, 这是一个简单的答案,

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. 托管内容页面的母版页将这些页面包装在更新面板中,因此为什么我的代码未获取文件上载控件的内容,而是执行异步回发而不是完整回发。

Thanks anyway @Shai 无论如何谢谢@Shai

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM