使用带图像的文件上载控件更新面板

时间:2013-07-17 06:24:05

标签: c# file-upload updatepanel

我正在尝试创建我的应用程序,当我从下拉列表中选择项目并上传图像时,它不刷新整个页面,只刷新更新的部分。下面显示的代码适用于下拉列表但不适用于上传按钮。当我上传图片时,页面会不断刷新。请帮我看看我做错了什么,或者我忘记添加任何东西。谢谢!

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>

<asp:DropDownList ID="ddlPoliceID" runat="server"
            AutoPostBack="True" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlPoliceID_SelectedIndexChanged">
            <asp:ListItem Value="-1">--Select--</asp:ListItem>
            </asp:DropDownList>

<asp:Label ID="Label10" runat="server" Text="Rank:"></asp:Label>
            <br />
            <asp:Image ID="Image2" runat="server" />
            <br />
            <asp:FileUpload ID="FileUpload1" runat="server" />
            <br />
            <asp:Button ID="btnUpload1" runat="server" Text="Upload" OnClick="btnUpload1_Click" />
            <br />
            <asp:Label ID="lblUpload1" runat="server" Text=""></asp:Label>
            <br />

 </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="ddlPoliceID" EventName="SelectedIndexChanged" />
        <asp:PostBackTrigger ControlID="btnUpload1" />
    </Triggers>
    </asp:UpdatePanel>

1 个答案:

答案 0 :(得分:0)

这里的代码粗体是你想要的。

                                   - 选择 -                     --Foo--                      - 酒吧 -                     --Goo--                     

    <asp:Label ID="Label10" runat="server" Text="Rank:"></asp:Label>
    <br />
    <asp:Image ID="Image2" runat="server" />
    <br />
    <asp:FileUpload ID="FileUpload1" runat="server" />
    <br />
    <asp:Button ID="btnUpload1" runat="server" Text="Upload" OnClick="btnUpload1_Click" />
    <br />
    <asp:Label ID="lblUpload1" runat="server" Text=""></asp:Label>
    <br />
 </ContentTemplate>
<Triggers>
    <asp:AsyncPostBackTrigger ControlID="ddlPoliceID" EventName="SelectedIndexChanged" />
    **<asp:AsyncPostBackTrigger ControlID="btnUpload1" EventName="Click" />**
</Triggers>
</asp:UpdatePanel>