0

我有一个TabContainer其中每个选项卡都有一个ModalPopupExtender. 在每个里面ModalPopupExtender我定义了一个AsyncFileUpload.

我的目标是,当文件上传/失败时,它会在ModalPopupExtender显示这一事实的内部显示一个标签。另外,我想TabPanel用上传文件的信息更新对应的信息(在关闭之前或之后ModalPopupExtender,对我来说都是一样的)。

我认为问题出ModalPopupExtenderContentTemplate's内部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" />:&nbsp;
    <asp:Label ID="lBrochureCurrentFileName" runat="server" Text="" /><br />

    <asp:Label ID="lBrochureCurrentDateTag" runat="server" Text="Upload Date" CssClass="LabelForTextBox" />:&nbsp;
    <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))

工作正常。

谢谢!

4

1 回答 1

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/

它不完全是您正在寻找的东西,但它应该会有所帮助。希望能帮助到你。

于 2012-10-26T12:48:17.520 回答