Asp.net中UpdatePanel内包含FileUpload的使用

在Asp.net中UpdatePanel内包含FileUpload文件上传控件时候,在提交时,FileUpload控件中选择的文件不会被提交,需要在UpdatePanel进行设置,具体代码如下: [ 需添加 <Triggers> 属性]

<asp:UpdatePanel ID="UpdatePanel4" runat="server">
                    <ContentTemplate>
                        <table width="80%">
                    <tr>
                        <td class="title" colspan="2">添加新产品</td>
                    </tr>
                    <tr>
                        <td align="right" style="width:120px;">产品编码:</td>
                        <td align="left">
                            <asp:TextBox ID="txtProductCoder" runat="server" AutoPostBack="True" 
                                Width="350px" ontextchanged="txtProductCoder_TextChanged"></asp:TextBox>
                            &nbsp;<asp:CustomValidator ID="cvProductCoder" runat="server" 
                                ControlToValidate="txtProductCoder" Display="Dynamic" ErrorMessage="请输入产品编码!"></asp:CustomValidator>
                            <asp:CustomValidator ID="cvCoderIsExists" runat="server" 
                                ControlToValidate="txtProductCoder" Display="Dynamic" 
                                ErrorMessage="该产品编码已经存在,请重新输入!"></asp:CustomValidator>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">产品名称:</td>
                        <td align="left">
                            <asp:TextBox ID="txtProductName" runat="server" Width="350px"></asp:TextBox>
                            &nbsp;<asp:CustomValidator ID="cvProductName" runat="server" 
                                ControlToValidate="txtProductName" Display="Dynamic" ErrorMessage="请输入产品名称!"></asp:CustomValidator>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">产品类型:</td>
                        <td align="left">
                            <asp:DropDownList ID="ddlProductType" runat="server" 
                                DataSourceID="ODSAddProductType" DataTextField="productType_name" 
                                DataValueField="productType_id" Width="350px">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">产品型号:</td>
                        <td align="left">
                            <asp:TextBox ID="txtProductModel" runat="server" Width="350px"></asp:TextBox>
                            <asp:CustomValidator ID="cvProductModel" runat="server" 
                                ControlToValidate="txtProductModel" Display="Dynamic" ErrorMessage="请输入产品型号!"></asp:CustomValidator>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">产品规格:</td>
                        <td align="left">
                            <asp:TextBox ID="txtProductStandard" runat="server" Width="350px"></asp:TextBox>
                            &nbsp;<asp:CustomValidator ID="cvProductStandard" runat="server" 
                                ControlToValidate="txtProductStandard" Display="Dynamic" 
                                ErrorMessage="请输入产品规格!"></asp:CustomValidator>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">产品图片:</td>
                        <td align="left">
                            <asp:FileUpload ID="fuProductImage" runat="server" Width="350px" />
                            &nbsp;<asp:CustomValidator ID="cvUpdateImage" runat="server" 
                                ControlToValidate="fuProductImage" Display="Dynamic" ErrorMessage="上传失败!"></asp:CustomValidator>
                        </td>
                    </tr>
                    <tr>
                        <td align="right" valign="top">产品备注:</td>
                        <td align="left">
                            <asp:TextBox ID="txtProductRema" runat="server" Height="60px" 
                                TextMode="MultiLine" Width="550px"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" align="center">
                            <asp:Button ID="btnAddProduct" runat="server" Text="添加" 
                                onclick="btnAddProduct_Click" />
&nbsp;<input id="Reset2" type="reset" value="重置" />
                            <input id="Button2" type="button" value="关闭" /><br />
                            <asp:Label ID="lblAddProductInfo" runat="server" ForeColor="#006600"></asp:Label>
                        </td>
                    </tr>
                </table>
                </ContentTemplate>
                <Triggers>
                    <asp:PostBackTrigger ControlID ="btnAddProduct" /> <!-- btnAddProduct为提交按钮 -->
                </Triggers>
                </asp:UpdatePanel>
                </div>

你可能感兴趣的:(Asp.net中UpdatePanel内包含FileUpload的使用)