本文介绍了使用ajax(更新面板和脚本管理器)进行文件上传控制.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在页面中插入ajax功能,但是当我将文件上载控件放在更新面板中时..它对我来说不再起作用..甚至没有数据插入..

但没有ajax(更新面板和脚本管理器).该代码工作正常..

如何解决这个问题.我只希望文件上传控件可与ajax(更新面板和脚本管理器一起使用


这是我的代码


i want to insert ajax fucntionality in my page but as i put the file upload control in update panel.. it will no long work for me..even data is not inserted..

but without ajax( update panel and script manager). The Code works Fine..

How to sort out that problem. i just want file upload control to work with ajax( update panel and Script manager


here is my code


<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
    .style4
    {
        width: 100%;
    }
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <p>
        Add new Products:</p>
<uc1:nav ID="nav1"  runat="server" />
<p align="center">
         </p>
<p align="center">
        <asp:Label ID="UploadStatusLabel" runat="server"></asp:Label>
</p>
<table class="style4">
    <tr>
        <td>
            Category Name:</td>
        <td>
        <asp:DropDownList ID="DropDownList1" runat="server" Height="20px" Width="170px">
        </asp:DropDownList>
        </td>
    </tr>
    <tr>
        <td>
            Product Name:</td>
        <td>
        <asp:TextBox ID="txtproname" runat="server" Width="174px"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtproname" 

            ErrorMessage="Please Enter Product Name" Display="Dynamic">*</asp:RequiredFieldValidator>

        </td>
    </tr>
    <tr>
        <td>
            Product Image:</td>
        <td>
        <asp:FileUpload ID="FileUpload1" runat="server" Width="218px" />
        </td>
    </tr>
    <tr>
        <td>
            Product Price:</td>
        <td>
        <asp:TextBox ID="txtproprice" runat="server" Width="138px"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td>
            Description :</td>
        <td>
        <asp:TextBox ID="txtprodesc" runat="server" Height="50px" Width="267px" 

            TextMode="MultiLine"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtprodesc" 

            ErrorMessage="Enter Product Description" Display="Dynamic">*</asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td>
            Original Price</td>
        <td>
            <asp:TextBox ID="txtOrigional" runat="server" Width="136px"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td>
            Stock Quantity</td>
        <td>
            <asp:DropDownList ID="dpquantity" runat="server">
                <asp:ListItem>0</asp:ListItem>
                <asp:ListItem>10</asp:ListItem>
                <asp:ListItem>20</asp:ListItem>
                <asp:ListItem>50</asp:ListItem>
                <asp:ListItem>100</asp:ListItem>
            </asp:DropDownList>
        </td>
    </tr>
    <tr>
        <td colspan="2">
<p align="center">
         <asp:Button ID="btnaddproduct" CausesValidation="true" runat="server" onclick="btnaddproduct_Click" 

            Text="Add Product" Width="115px" />
    
        </p>
        </td>
    </tr>
    <tr>
        <td align="center" colspan="2">
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
        </td>
    </tr>
</table>
    <p align="center">
        <asp:Label ID="lblresult" runat="server"></asp:Label>
    </p>
    <p align="center">
        To Order for Product Click Me:<asp:LinkButton ID="orderpro" runat="server" CausesValidation="false" 

            onclick="orderpro_Click">ClickMe</asp:LinkButton>
    </p>
    <p align="center">
         </p>
    <p align="center">
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 

            AutoGenerateColumns="False" onrowcancelingedit="_rowcancel" 

            onrowdeleting="_rowdeleting" onrowediting="_rowediting" 

            onrowupdating="_rowupdating" Width="446px" 

            onpageindexchanging="_pagechange" HorizontalAlign="Center" 

            onselectedindexchanged="GridView1_SelectedIndexChanged">
            <Columns>
                <asp:TemplateField HeaderText="ProductID">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtproid" runat="server" Text='<%# Eval("ProductID") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblproid" runat="server" Text='<%# Eval("ProductID") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="ProductName">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtproname" runat="server" Text='<%# Eval("ProductName") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblproname" runat="server" Text='<%# Eval("ProductName") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="UnitCost">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtproprice" runat="server" Text='<%# Eval("UnitCost") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblproprice" runat="server" Text='<%# Eval("UnitCost") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CommandField ShowEditButton="True" />
                <asp:CommandField ShowDeleteButton="True" />
            </Columns>
        </asp:GridView>
    </p>
    <p align="center">
         </p>
    <p align="center">
         </p>
    <p>
         </p>
    <p>
         </p>
    <p>
         </p>
</asp:Content>

推荐答案

<asp:updatepanel ...="" xmlns:asp="#unknown">
    <trigger>
        <asp:postbacktrigger controlid="btnaddproduct" />

</trigger></asp:updatepanel>



页面的其余部分仅适用于使用普通回发的添加"按钮进行异步回发.

另一种可能性是使用Telerik的文件上传控件.专门用于与上传进度栏异步工作.



The rest of the page will work with Asynchronous postbacks only for the Add button a normal postback is used.

Another possibility is to use the fileupload control of Telerik. That is specifically designed to work asynchronously with an upload progress bar.


这篇关于使用ajax(更新面板和脚本管理器)进行文件上传控制.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 14:44