母版页中的更新面板和子页面中的asp文件上载

时间:2012-08-04 08:59:00

标签: c# asp.net html ajax

我遇到了一个问题,目前我的主页面和我的子页面中有一个更新面板我正在使用asp文件上载控件。

我在主人的更新面板p [年龄:

    <form id="form1" runat="server">
      <asp:ScriptManager ID="ScriptManager1" runat="server">
     </asp:ScriptManager>

     <asp:updateprogress associatedupdatepanelid="UpdatePanel1"
        id="updateProgress" runat="server">
         <progresstemplate>
            <div id="processMessage" style=" background-image:url('../../Styles/ajax-loader3.gif'); width:100px; height:100px; background-repeat:no-repeat; background-position:center;">

               </div>
        </progresstemplate>
    </asp:updateprogress> 

    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
     <ContentTemplate>
..
    </ContentTemplate>
 </asp:UpdatePanel>
</form>

My Child页面需要文件上载:

<div id="Annoucments" class="ContentDIV">
            <h2 class="Tabheader">Annoucments</h2>
            <p class="tabdescription">Here you will be able to upload announcements and pictures to be displayed in the login page, below is the current announcement click on update to save the changes that you have made.</p>

            <table width = "100%">

            <tr>
            <td class="Tablabel">Annoucment title:</td> <td class="tableInput" align="left"><asp:TextBox ID="Announcement_TB" runat="server" CssClass="textboxTabs"></asp:TextBox></td>
            <td class="Tablabel">Picture/Poster:</td> <td class="tableInput" align="left"><asp:FileUpload ID="Announcement_PIC" runat="server"  CssClass="textboxTabsFiles"/></td>
            </tr>

            <tr>
            <td class="Tablabel">Description:</td> <td class="tableInput" align="left"><asp:TextBox ID="Announcement_Desc" CssClass="textboxTabs" runat="server" Rows="3" TextMode="MultiLine"></asp:TextBox></td>
            </tr>

            <tr><td colspan="4" style="height:10px" id ="BLANK">
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                </td></tr>

            <tr>
            <td colspan="2" align="right"><input type="button" id="Announcement_Update" runat="server" value="Update" class="TabButton" onserverclick="ANNOUNCEMENT_UPDATE_Click" style=" font-size:smaller"/></td><td colspan="2">&nbsp;&nbsp;<input type="button" ID="ANNOUNCEMENT_Cancel" runat="server" value="Cancel" class="TabButton" style=" font-size:smaller"/></td>  
            </tr>

            </table>

        </div>

*当我点击按钮Announcement_Update后端代码将被触发以获取我的文件名时,返回的文件名将始终在调试时找到。*

4 个答案:

答案 0 :(得分:8)

将此代码放在子页面中,以传递PostBackTrigger以进行文件上传。

protected void Page_Load(object sender, EventArgs e)
{
    UpdatePanel updatePanel = Page.Master.FindControl("UpdatePanel1") as UpdatePanel;
    UpdatePanelControlTrigger trigger  = new PostBackTrigger();
    trigger.ControlID = Announcement_Update.UniqueID;
    updatePanel.Triggers.Add(trigger);
}

享受编码:)

答案 1 :(得分:0)

您无法在filename

中获得UpdatePanel

从您的代码中删除UpdatePanel或使用Asynchronous File Uploader

或者你可以使用Ajax File Uploading techniques但这有点棘手。

答案 2 :(得分:0)

由于回发问题,Asp UpdatePanel无法在更新面板内工作。 您可以使用与上传器关联的按钮添加触发器,如

    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:Button ID="Button1" runat="server" Text="Click" />
                </ContentTemplate>
                <Triggers>
                    <asp:PostBackTrigger ControlID="Button1" />
                </Triggers>
            </asp:UpdatePanel>

答案 3 :(得分:0)

如果您添加Trigger,它对我有用,但也要确保编辑以形成包含以下内容的标记:

<form runat="server" enctype="multipart/form-data">