0
我的问题是一个简单的答案,我希望。FileUpload控件无法正常工作'外部'AJAX更新面板,但工作'内部'与回传触发器?
我正在制作一个带有文件上传控件的简单表格,该文件首先在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>
</td>
<td>
<asp:ImageButton ID="btnSelect" runat="server" SkinID="selectprobationdoc"/>
</td>
<td class="standardLabel" style ="width:200px">Select documents</td>
</tr>
<tr>
<td>
</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>
</td>
<td>
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" CausesValidation="False" />
</td>
</tr>
<tr>
<td>
</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>
原谅格式化我删除了空格!
现在,当我的标记是这样的,我调用FileHandler上的.HasFile()它返回一个空值?
当我添加以下
<asp:UpdatePanel ID="ContentPanel" UpdateMode="Conditional" runat="server" ChildrenAsTriggers="true">
<Triggers>
<asp:PostBackTrigger ControlID="btnSave" />
</Triggers>
<ContentTemplate>
*Markup as above*
我可以得到控制的内容。我知道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
}
}
上面是检查背后的初始代码,这从未改变从ading更新面板。
有人能帮我理解我错过了什么吗?
感谢
让我猜猜,'pnlUpload'是不可见的,在启动客户端,但在某些时候,你设置它的visibily为'真'(或展示给客户以某种方式另一个),正确吗? – Shai 2012-07-19 11:28:01
yes纠正其隐藏起来 – dotnetnewb 2012-07-19 11:35:21
好吧,试着将这一行添加到您的'Page_Load'事件中:'ScriptManager.GetCurrent(this).RegisterPostBackControl(uplDoc);' – Shai 2012-07-19 11:40:01