我是ASP.NET的新手,所以可能我的问题很容易......但是我浪费了很多时间而没有成功。
我的部分内容是
<asp:UpdatePanel ID="pnlFileUpload" runat="server">
<ContentTemplate>
<ajaxToolkit:AsyncFileUpload ID="upload" runat="server" OnUploadedComplete="upload_UploadedComplete"
OnUploadedFileError="upload_UploadedFileError" UploaderStyle="Modern" UploadingBackColor="Yellow"
Width="400px" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="pnlFileError" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblFileError" runat="server" Text="errFile" Visible="false"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="upload" EventName="UploadedComplete" />
</Triggers>
</asp:UpdatePanel>
当用户上传(以ajaxToolkit:AsyncFileUpload
开头)结束时,会调用upload_UploadedComplete
示例代码为:
protected void upload_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
int size = upload.PostedFile.ContentLength;
if (size > maxsize)
{
lblFileError.Text = 'File too big...';
lblFileError.ForeColor = System.Drawing.Color.Red;
lblFileError.Visible = true;
pnlFileError.Update();
}
}
但lblFileError
从未显示过......为什么?!?
答案 0 :(得分:0)
AsyncFileupload不需要updatePanel(不需要AJAx工具包控件)。因为他们把它作为内置的。删除fileupload UpdatePanel并再次测试
似乎你不能以这种方式做到这一点。基于AjaxControlToolkitSampleSite向用户显示有关上传文件的消息,您应该使用“ScriptManager.RegisterClientScriptBlock”,如下所示:
protected void upload_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
int size = upload.PostedFile.ContentLength;
if (size > maxsize)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "error", "top.$get(\"" + lblFileError.ClientID + "\").innerHTML = 'File too big...';", true);
}
}