This is a migrated thread and some comments may be shown as answers.

Problem: Endless AJAX request.

2 Answers 26 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
McHaimech
Top achievements
Rank 1
McHaimech asked on 16 Apr 2009, 07:28 PM
Greetings;

I have a webpage that contains the following:
  1. RadAjaxManager.
  2. Repeater.
  3. Datalist, inside that repeater that's being populted dynamically on repeater's itemDatabound.
  4. Label.

Inside every datalist row there is a button that initiates DataList ItemCommand, where it updates the label.
Inside repeater ItemDataBound I am adding the AjaxSettings for the RadAjaxManager.

The problem is, when I click on the button that's inside the datalist, the loading panel shows up and never disappear.
Here is my ASPx code:

                                    <radA:RadAjaxManager ID="RadAjaxManager1" runat="server">  
                                    </radA:RadAjaxManager> 
                                    <asp:Repeater ID="rpCategories" runat="server" DataSourceID="dsCategories"   
                                        onitemdatabound="rpCategories_ItemDataBound">  
                                        <HeaderTemplate> 
                                            <table width="100%" cellpadding="0" cellspacing="0" border="1" bordercolor="#ffffff">  
                                        </HeaderTemplate> 
                                        <ItemTemplate> 
                                            <tr> 
                                                <td> 
                                                    <asp:Literal ID="litCatID" runat="server" Text='<%# Eval("CategoryID") %>' Visible="false"></asp:Literal> 
                                                    <asp:Image runat="server" ID="imgCat" ImageUrl='<%# Eval("CategoryImage")%>' Width="100px" /> 
                                                    <asp:label runat="server" CssClass="CatName" id="lblCatName" Text='<%# Eval("CategoryName")%>'></asp:label> 
                                                </td> 
                                            </tr> 
                                            <tr> 
                                                <td> 
                                                    <asp:label runat="server" CssClass="CatDesc" id="lblCatDesc" Text='<%# Eval("CategoryDesc")%>'></asp:label> 
                                                </td> 
                                            </tr> 
                                            <tr> 
                                                <td> 
                                            <asp:DataList OnItemCommand="dlItems_OnItemCommand" DataKeyField="ProductID" ID="dlItems" Width="100%" runat="server">  
                                                <HeaderTemplate> 
                                                    <table width="100%" cellpadding="0" cellspacing="2">  
                                                </HeaderTemplate> 
                                                <ItemTemplate> 
                                                    <tr style="background-color:#e6caae;">  
                                                        <td valign="top">  
                                                            <asp:Literal ID="litProductID" runat="server" Text='<%# Eval("ProductID") %>' visible="false"></asp:Literal> 
                                                            <asp:Label ID="lblModelName" runat="server" Text='<%# Eval("ModelName") %>' CssClass="ItemName"></asp:Label> 
                                                        </td> 
                                                        <td width="50">  
                                                            <asp:Label ID="lblUnitCost" runat="server" Text='<%# Eval("UnitCost") + "/person" %>' CssClass="ItemDesc"></asp:Label> 
                                                        </td> 
                                                        <td width="50" rowspan="2">  
                                                            <asp:Button CommandName="AddToBasket" CommandArgument='<%# Eval("ProductID") %>' ID="btnAddToBasket" runat="server" Text="Add to basket" /> 
                                                        </td> 
                                                    </tr> 
                                                    <tr style="background-color:#e6caae;">  
                                                        <td colspan="2" valign="top">  
                                                            <asp:Label ID="lblDesc" runat="server" Text='<%# Eval("Description") %>' CssClass="ItemDesc"></asp:Label> 
                                                        </td> 
                                                    </tr> 
                                                    <tr style="background-color:#e6caae;">  
                                                        <td colspan="3">  
                                                            <span class="ItemDesc"># of persons:</span> <asp:TextBox ID="txtPersons" runat="server" Text="1"></asp:TextBox> 
                                                        </td> 
                                                    </tr> 
                                                    <tr style="background-color:#e6caae;">  
                                                        <td colspan="3">  
                                                            <span class="ItemDesc">Notes:</span> <asp:TextBox ID="txtNotes" runat="server" Text="" style="width:83%"></asp:TextBox> 
                                                        </td> 
                                                    </tr> 
                                                    <tr> 
                                                        <td colspan="3"><hr /></td>  
                                                    </tr> 
                                                </ItemTemplate> 
                                                <FooterTemplate> 
                                                    </table> 
                                                </FooterTemplate> 
                                            </asp:DataList> 
                                        </ItemTemplate> 
                                        <FooterTemplate> 
                                                    </td> 
                                                </tr> 
                                            </table> 
                                        </FooterTemplate> 
                                    </asp:Repeater> 
                                    <asp:SqlDataSource ID="dsCategories" runat="server"   
                                        SelectCommand="SELECT * FROM [CMRC_Categories] ORDER BY [SortNo]">  
                                    </asp:SqlDataSource> 
                                </td> 
                                <td style="width:30%" valign="top">  
                                    <div id="MiniBasket" style="position:relative">  
                                        <asp:DataList ID="dlBasket1" runat="server" DataSourceID="dsOrder"   
                                            BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"   
                                            CellPadding="3" CellSpacing="2" GridLines="Both">  
                                            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" /> 
                                            <ItemStyle BackColor="#FFF7E7" ForeColor="#8C4510" /> 
                                            <SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" /> 
                                            <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" /> 
                                            <ItemTemplate> 
                                                <table cellspacing="1" class="style1">  
                                                    <tr> 
                                                        <td> 
                                                            <asp:Label ID="lblITem" runat="server" Text='<%# Eval("ModelName") %>'></asp:Label> 
                                                        </td> 
                                                        <td> 
                                                            <asp:Label ID="lblQuan" runat="server" Text='<%# Eval("Quantity") %>'></asp:Label> 
                                                        </td> 
                                                        <td><asp:Button ID="Button1" runat="server" Text="Button" /></td>  
                                                    </tr> 
                                                </table> 
                                            </ItemTemplate> 
                                        </asp:DataList> 
                                        <asp:Label ID="lblCount" runat="server" Text="0"></asp:Label> 
                                        <asp:SqlDataSource ID="dsOrder" runat="server"   
                                            SelectCommand="SELECT dbo.CMRC_ShoppingCart.UserName, dbo.CMRC_ShoppingCart.IsCheckedOut, dbo.CMRC_ShoppingCartItems.Quantity, dbo.CMRC_ShoppingCartItems.ModelName, dbo.CMRC_ShoppingCartItems.Price, dbo.CMRC_ShoppingCartItems.BasketItemID, dbo.CMRC_ShoppingCart.cartID FROM dbo.CMRC_ShoppingCart INNER JOIN dbo.CMRC_ShoppingCartItems ON dbo.CMRC_ShoppingCart.cartID = dbo.CMRC_ShoppingCartItems.CartID WHERE (dbo.CMRC_ShoppingCart.IsCheckedOut = 0) AND (dbo.CMRC_ShoppingCart.UserName = @Username)">  
                                        </asp:SqlDataSource> 

And here is the codebehind:

    public partial class Order : System.Web.UI.Page  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            dsCategories.ConnectionString = LesPreasso.Properties.Settings.Default.ConnectionString;  
            dsOrder.ConnectionString = LesPreasso.Properties.Settings.Default.ConnectionString;  
            dsOrder.SelectParameters.Add("username"this.User.Identity.Name);  
        }  
 
        protected void rpCategories_ItemDataBound(object sender, RepeaterItemEventArgs e)  
        {  
            DataList dl = new DataList();  
            Literal pcatid;  
            dl = (DataList)(e.Item.FindControl("dlItems"));  
            pcatid = (Literal)e.Item.FindControl("litCatID");  
            if (!(dl ==null))  
            {  
                DataSet oData = new DataSet();  
                SqlConnection conn = new SqlConnection();  
                conn.ConnectionString = LesPreasso.Properties.Settings.Default.ConnectionString;  
                SqlDataAdapter cmd = new SqlDataAdapter("select * from CMRC_Products where CategoryID=@CategoryID", conn);  
                cmd.SelectCommand.Parameters.AddWithValue("CategoryID", pcatid.Text);  
                cmd.Fill(oData);  
                if (oData.Tables[0].Rows.Count > 0)  
                {  
                    dl.DataSource = oData.Tables[0].DefaultView;  
                    dl.DataBind();  
                }  
                RadAjaxManager1.AjaxSettings.AddAjaxSetting(dl, lblCount, LoadingPanel1);  
            }  
        }  
 
        protected void dlItems_OnItemCommand(object sender, DataListCommandEventArgs e)  
        {  
            if (e.CommandName=="AddToBasket")  
            {  
                lblCount.Text= Convert.ToString(Convert.ToInt32(lblCount.Text)+ 1);  
            }  
        }  
    }  

2 Answers, 1 is accepted

Sort by
0
James Rintoul
Top achievements
Rank 1
answered on 21 Apr 2009, 12:02 PM
Can't see any error handling here as are you sure there is no error being encountered during the post back? I think by default, the ajax call will not redirect to an error page so your reponse is never returning successfully and turning the ajax panel off.
0
McHaimech
Top achievements
Rank 1
answered on 22 Apr 2009, 11:33 AM
Thank James Rintoul for your reply:

If I remove the line that adds the Ajax settings in the code-behind file:
RadAjaxManager1.AjaxSettings.AddAjaxSetting(dl, lblCount, LoadingPanel1); 
The code runs smoothly and without any errors, but when I add it to the AJAX settings everything stops working as described in my previous post.

Thank you in advance.

Best regards;
MM
Tags
Ajax
Asked by
McHaimech
Top achievements
Rank 1
Answers by
James Rintoul
Top achievements
Rank 1
McHaimech
Top achievements
Rank 1
Share this question
or