Click here to Skip to main content
15,923,006 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.NET
<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>
Posted

1 solution

It does not work because the fileupload data is not send to the server when doing an asynchronous postback. One solution is to use an UpdatePanel and register the button control that should upload to file to the server, as a Postback control in the triggers section of the updatepanel:

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


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.
 
Share this answer
 
v2
Comments
codegeekalpha 12-Dec-11 12:40pm    
??
codegeekalpha 12-Dec-11 13:00pm    
The data is inserted now.. but the ajax functionality is still not working with Add product button
K Herms 13-Dec-11 4:42am    
No that is what the postbacktrigger does. It makes sure that the control in the postbacktrigger is executed as synchronous postback instead of a asynchronous postback.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900