我有一个TabContainer
,其中每个标签都有一个ModalPopupExtender
。在每个ModalPopupExtender
内,我定义了一个AsyncFileUpload
。
我的目标是,当文件上传/失败时,它会在ModalPopupExtender
内显示一个显示此事实的标签。另外,我想更新相应的TabPanel
以及有关上传文件的信息(在关闭ModalPopupExtender
之前或之后,对我来说也是一样)。
我认为问题在于ModalPopupExtender
ContentTemplate
内部TabPanel
,但我不知道解决方案。
我的标记代码:
<AjaxControlToolkit:TabPanel ID="tBrochure" runat="server" HeaderText="Brochure" OnDemandMode="Always" EnableViewState="true">
<ContentTemplate>
<asp:Label ID="lBrochureDesc" runat="server" Text="In this tab you can set or update the brochure document and its description for the Maintenance Contracts product." /><br /><br />
<asp:Label ID="lBrochureCurrentFile" runat="server" Text="Current File" CssClass="LabelForTextBox" />:
<asp:Label ID="lBrochureCurrentFileName" runat="server" Text="" /><br />
<asp:Label ID="lBrochureCurrentDateTag" runat="server" Text="Upload Date" CssClass="LabelForTextBox" />:
<asp:Label ID="lBrochureCurrentDate" runat="server" Text="" /><br /><br />
<asp:Panel ID="pBrochureUploadFileLink" runat="server" style="margin-left: 20px;">
<asp:ImageButton ID="ibBrochureUploadFile" runat="server" ImageUrl="~/Images/icon_add.png" Width="20px" style="vertical-align: middle" />
<asp:Label ID="lBrochureUploadFile" runat="server" Text="Upload a new document" style="vertical-align: middle" /><br />
</asp:Panel>
<asp:Panel ID="pBrochureUploadFilePopup" runat="server" CssClass="Popup" style="display:none;">
<asp:Panel ID="pBrochureUploadFilePopupTitleBar" runat="server" CssClass="PopupTitleBar">
<asp:ImageButton ID="imBrochureUploadFilePopupClose" runat="server" ImageUrl="~/Images/icon_close.png" />
</asp:Panel>
<asp:Panel ID="pBrochureUploadFilePopupContent" runat="server" CssClass="PopupContent">
<asp:Label ID="lBrochureUploadFilePopupTitle" runat="server" CssClass="title" Text="Upload a new file" />
<AjaxControlToolkit:AsyncFileUpload ID="fuBrochure" runat="server" CompleteBackColor="Green" ErrorBackColor="Red" /><br /><br />
<asp:Label ID="lBrochureUploadFileStatus" runat="server" Text="" />
<asp:Label ID="lBrochureUploadFileAdvice" runat="server" Text="The current file will be replaced but a backup of that version will be stored." />
</asp:Panel>
</asp:Panel>
<asp:Button ID="bBrochureDummy" runat="server" style="display:none;" />
<AjaxControlToolkit:ModalPopupExtender ID="mpeBrochureUpload" runat="server" ClientIDMode="Static"
TargetControlID="pBrochureUploadFileLink"
PopupControlID="pBrochureUploadFilePopup"
CancelControlID="imBrochureUploadFilePopupClose"
PopupDragHandleControlID="pBrochureUploadFilePopupTitleBar"
BackgroundCssClass="PopupBackground" DropShadow="true" />
<br /><br />
<asp:Label ID="lBrochureDescription" runat="server" Text="Description" CssClass="LabelForTextBox" />:<br />
<asp:TextBox ID="tbBrochureDescription" runat="server" TextMode="MultiLine" CssClass="TextBox" Style="height:50px; width:200px; max-width: 900px;"/><br /><br />
<asp:LinkButton ID="lbBrochureSave" runat="server" Text="Save" CssClass="ButtonWithArrow" />
<asp:LinkButton ID="lbBrochureCancel" runat="server" Text="Cancel" CssClass="ButtonWithArrow" />
</ContentTemplate>
</AjaxControlToolkit:TabPanel>
我的代码隐藏:
Protected Sub fuBrochure_UploadedComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs) Handles fuBrochure.UploadedComplete
If fuBrochure.HasFile Then
Dim fileName As String = fuBrochure.FileName
Dim fileType As String = fuBrochure.ContentType
If Products.updateDoc(productId, Products.DocumentId.Brochure, fileName, fileType) Then
fuBrochure.SaveAs(MapPath(path + fileName))
End If
UpdateBrochurePanel()
lBrochureUploadFileStatus.Text = "File uploaded succesfully!"
mpeBrochureUpload.Hide()
End If
End Sub
Protected Sub fuBrochure_UploadedFileError(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs) Handles fuBrochure.UploadedFileError
lBrochureUploadFileStatus.Text = "Error!"
End Sub
在此代码中,行:
lBrochureUploadFileStatus.Text = "File uploaded succesfully!"
mpeBrochureUpload.Hide()
没有做任何事情,但行
fuBrochure.SaveAs(MapPath(path + fileName))
工作正常。
谢谢!
答案 0 :(得分:1)
AsyncFileUpload控件使用iframe将文件发布到服务器。这意味着,在上传文件时,页面上没有任何内容被回发。这是您的标签未更新的原因
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "size", "top.$get(\"" + lBrochureUploadFileStatus.ClientID + "\").innerHTML = 'File uploaded succesfully!';", true);
你可以在这里找到一个简单的例子http://technico.qnownow.com/using-asyncfileupload-control-in-asp-net-ajax/
这不完全是你想要的,但它应该有所帮助。希望它有所帮助。