Problem with RadAjaxManagerProxy

10 posts, 0 answers
  1. nhaydon
    nhaydon avatar
    35 posts
    Member since:
    May 2007

    Posted 18 Sep 2007 Link to this post

    I am adding a control to the Proxy for each GridRow. Problem is, it is only working on the first row. The rest of the rows act like they are not Ajaxified. The update button is working correctly. It is just the btnDelete button that is not working on subsequent rows.


    protected void Page_PreRender(object sender, EventArgs e)  
        {  
     
            //Find a user-control in the master page  
            UserControl cartSummary = ((UserControl)Master.FindControl("CartSummary1"));  
            //Update Cart Summary when updateButton is clicked  
            RadAjaxManagerProxy1.AjaxSettings.AddAjaxSetting(updateButton, cartSummary);  
     
            foreach (GridViewRow row in grid.Rows)  
            {  
                    ImageButton btn = ( ( ImageButton )row.FindControl( "btnDelete" ) );  
                    RadAjaxManagerProxy1.AjaxSettings.AddAjaxSetting( btn, cartSummary );  
            }  
            
         
        } 
  2. Plamen Peshev
    Admin
    Plamen Peshev avatar
    886 posts

    Posted 20 Sep 2007 Link to this post

    Hi nhaydon,

    I made a simple project based on your code which illustrates that everything works as expected at our side.
    Please see the attached project for your reference. What is different in your case?


    All the best,
    Plamen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. nhaydon
    nhaydon avatar
    35 posts
    Member since:
    May 2007

    Posted 20 Sep 2007 Link to this post

    The most notable difference is that I am loading the usercontrol on a masterpage and grabbing that usercontrol and adding that to the proxy.

    Your sample application does not include masterpages.
  5. nhaydon
    nhaydon avatar
    35 posts
    Member since:
    May 2007

    Posted 20 Sep 2007 Link to this post

    Think I figured out the problem. It seems like only the first row in the grid was "Ajaxified". As soon as I Ajaxed the entire grid, it is working fine.

            RadAjaxManagerProxy1.AjaxSettings.AddAjaxSetting( grid, cartSummary );  
     

    Now it is working as expected. I want this anyway because I have a textbox in the grid that you can update quantities for the usercontrol cart that is in the masterpage.
  6. John
    John avatar
    416 posts
    Member since:
    Oct 2006

    Posted 21 Sep 2007 Link to this post

    hi

    Take a look at these online resource to see how to ajaxify particular template GridView controls:

    http://www.telerik.com/help/radcontrols/prometheus/?ajxAjaxifyParticularTemplatedGridViewButtons.html



    Regards...
    [John Peel]
  7. nhaydon
    nhaydon avatar
    35 posts
    Member since:
    May 2007

    Posted 21 Sep 2007 Link to this post

    This is really driving me nuts. It works when I add the grid to the AjaxManagerProxy but when I add individual controls, it only works on the first row. I watched the RadAjaxManagerProxy.AjaxSettings collection and it has all of the buttons, but for some reason the rest of the rows do not work. Could it be problem with the proxy?
  8. nhaydon
    nhaydon avatar
    35 posts
    Member since:
    May 2007

    Posted 21 Sep 2007 Link to this post

    After debugging, the UserControl on the masterpage is being called but the control is not being refreshed on the page, so the AJAX request is working but the control is just not refreshing.
  9. John
    John avatar
    416 posts
    Member since:
    Oct 2006

    Posted 21 Sep 2007 Link to this post

    hello,

    Hum, interesting problem...
    Could you please paste your code here, both *.aspx an *.cs?

    ...
    [John Peel]




  10. nhaydon
    nhaydon avatar
    35 posts
    Member since:
    May 2007

    Posted 21 Sep 2007 Link to this post

    What is even stranger is I have textboxes in the grid and those update the usercontrol fine. I am investigating if it has something to do with deleting rows from the grid, which is what I am having a problem with.

    <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="ShoppingCart.aspx.cs" Inherits="MemberPages_ShoppingCart" Title="Shopping Cart" %> 
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
     
    <%@ Register Src="~/UserControls/ProductRecommendations.ascx" TagName="ProductRecommendations" TagPrefix="uc1" %> 
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">  
        <%--<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">  
    </asp:ScriptManagerProxy>--%> 
        <%--<telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">  
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="grid">  
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="statusLabel" /> 
                        <telerik:AjaxUpdatedControl ControlID="grid" /> 
                        <telerik:AjaxUpdatedControl ControlID="titleLabel" /> 
                        <telerik:AjaxUpdatedControl ControlID="updateButton" /> 
                        <telerik:AjaxUpdatedControl ControlID="checkoutButton" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
                <telerik:AjaxSetting AjaxControlID="updateButton">  
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="statusLabel" /> 
                        <telerik:AjaxUpdatedControl ControlID="grid" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
            </AjaxSettings> 
        </telerik:RadAjaxManagerProxy>--%> 
       <br /> 
        <asp:Label ID="titleLabel" runat="server" Text="Your Shopping Cart" CssClass="SubTitleGreenSmall" /> 
           <%--<br />--%>    
         <hr style="width: 100%; height: 1px;"   /> 
          
        <asp:Label ID="statusLabel" CssClass="SubTitleBlue"  runat="server" /><br /> 
        
      <asp:GridView ID="grid" runat="server" BorderWidth="1px" AutoGenerateColumns="False" DataKeyNames="prdno" Width="100%"  OnRowDeleting="deleteItemFromCart" ShowFooter="True" OnRowDataBound="grid_RowDataBound" OnRowCreated="grid_RowCreated">  
            <PagerSettings Mode="NextPrevious" NextPageText="Next" PreviousPageText="Previous"/>  
        <Columns> 
          <asp:BoundField DataField="prdno" HeaderText="ProductID" ReadOnly="True" SortExpression="prdno" > 
            <ControlStyle Width="100%" /> 
          </asp:BoundField>        
          <asp:BoundField DataField="descp" HeaderText="Product Name" ReadOnly="True" SortExpression="Name" > 
            <ControlStyle Width="100%" /> 
          </asp:BoundField> 
            
          <asp:BoundField DataField="listprice" HtmlEncode="False" DataFormatString="{0:c}" HeaderText="Price" ReadOnly="True" 
            SortExpression="listprice" > 
              <ControlStyle Width="100%" /> 
              <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" /> 
              <HeaderStyle HorizontalAlign="Left" /> 
          </asp:BoundField> 
              
          <asp:TemplateField HeaderText="Quantity">  
             
              <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" /> 
              <HeaderStyle HorizontalAlign="Left" /> 
            <ItemTemplate> 
              <asp:TextBox ID="editQuantity" runat="server" CssClass="GridEditingRow" Width="24px" MaxLength="3" Text='<%#Eval("Quantity")%>' /> 
               <asp:RequiredFieldValidator ID="RequiredFieldValidator3" ControlToValidate="editQuantity" ValidationGroup="cartQuantityValidationGroup" Display="Dynamic" Font-Size="X-Small" runat="server" ErrorMessage="Required field."></asp:RequiredFieldValidator>    
               <asp:RegularExpressionValidator ID="RegularExpressionValidator4" ValidationGroup="cartQuantityValidationGroup" runat="server" Font-Size="X-Small" Display="Dynamic" ControlToValidate="editQuantity" 
                   ErrorMessage="Must be a whole number" SetFocusOnError="True" ValidationExpression="\d{1,7}"></asp:RegularExpressionValidator> 
            </ItemTemplate> 
          </asp:TemplateField> 
          <asp:BoundField DataField="utmes" HtmlEncode="False" HeaderText="UOM" ReadOnly="True" > 
              <ControlStyle Width="100%" /> 
               <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" /> 
              <HeaderStyle HorizontalAlign="Left" /> 
          </asp:BoundField> 
            <asp:TemplateField HeaderText="Subtotal" SortExpression="Subtotal">  
                <FooterTemplate> 
                    &nbsp;  
                </FooterTemplate> 
                <ItemStyle HorizontalAlign="Left" /> 
                <ItemTemplate> 
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("Subtotal", "{0:c}") %>'></asp:Label> 
                </ItemTemplate> 
            </asp:TemplateField> 
       <asp:TemplateField ShowHeader="False">  
               <ItemTemplate> 
                     <asp:ImageButton ID="btnDelete" ImageUrl="~/Images/BUDelete1.gif"  runat="server" CommandName="Delete" /> 
                             
               </ItemTemplate> 
           </asp:TemplateField> 
        </Columns> 
              
             <RowStyle BackColor="#EFF3FB" /> 
            <EditRowStyle BackColor="#2461BF" /> 
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> 
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> 
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> 
            <AlternatingRowStyle BackColor="White" /> 
      </asp:GridView> 
      <div class="Buttons">  
              
            <asp:ImageButton ID="continueShoppingButton" runat="server" ImageUrl="~/Images/Buttons/continueshopping_btn.gif"  OnClick="continueShoppingButton_Click" /> 
            
            <asp:ImageButton ID="checkoutButton" runat="server" ImageUrl="~/Images/Buttons/proceedtocheckout_btn.gif" OnClick="checkoutButton_Click"  /> 
      </div> 
      <div class="Buttons">  
                <asp:ImageButton ID="updateButton" runat="server" ImageUrl="~/Images/Buttons/updatequantities_btn.gif"   OnClick="updateCartItemQuantity"   /> 
      </div> 
      <div class="Payment">  
              &nbsp;  
       </div> 
      <div class="Payment">  
             &nbsp;</div> 
         
          
         
       <br /> 
       <br /> 
       <br /> 
       <br /> 
       <br /> 
         
       <div id="Recommendations">  
      <uc1:ProductRecommendations id="ProductRecommendations1" runat="server">  
      </uc1:ProductRecommendations> 
      </div> 
    </asp:Content> 
     


    using System;  
    using System.Data;  
    using System.Configuration;  
    using System.Collections;  
    using System.Web;  
    using System.Web.Security;  
    using System.Web.UI;  
    using System.Web.UI.WebControls;  
    using System.Web.UI.WebControls.WebParts;  
    using System.Web.UI.HtmlControls;  
    using BU.EStore.BAL;  
    using BU.EStore.Utilities;  
    using Telerik.Web.UI;  
    public partial class MemberPages_ShoppingCart : System.Web.UI.Page  
    {  
        decimal totalhours = 0;  
        RadAjaxManager ram;  
     
        protected void Page_Load(object sender, EventArgs e)  
        {  
            ram = ( ( RadAjaxManager )Master.FindControl( "RadAjaxManager1" ) );  
            UserControl cartSummary = ( ( UserControl )Master.FindControl( "CartSummary1" ) );  
            ram.AjaxSettings.AddAjaxSetting( grid, grid );  
            ram.AjaxSettings.AddAjaxSetting( updateButton, grid );  
            // populate the control only on the initial page load  
            if (!IsPostBack)  
                PopulateControls();  
        }  
     
        // fill shopping cart controls with data  
        private void PopulateControls()  
        {  
            // set the title of the page  
            this.Title = ConfigurationUtilities.SiteName + " : Shopping Cart";  
            // get the items in the shopping cart  
            DataTable dt = ShoppingCartBAL.GetItems();  
     
            ////Webservice call get the items in the shopping cart  
            //// Step 1: Instantiate the web service,  
            // localhost.wsBuckeye wsObject;  
            // wsObject = new localhost.wsBuckeye();  
     
            // //Step 2: Get the address of the web service which was automatically  
            // //written to the config file when a reference to it (web service)   
            // //was added to the application.  
            // DataTable dt;  
            // wsObject.Url = ConfigurationManager.AppSettings["localhost.wsBuckeye"];  
     
            // //Step 3: Call the method of the web service.  
            // dt = wsObject.GetItems(Membership.GetUser().ToString());  
            // if the shopping cart is empty...  
            if (dt.Rows.Count == 0)  
            {  
                titleLabel.Text = "Your shopping cart is empty!";  
                grid.Visible = false;  
                updateButton.Enabled = false;  
                checkoutButton.Enabled = false;  
                //totalAmountLabel.Text = String.Format("{0:c}", 0);  
            }  
            else  
            // if the shopping cart is not empty...  
            {  
                //Convert product description to proper case.  
                foreach (DataRow r in dt.Rows)  
                {  
                    r["descp"] = Helpers.ConvertStringToProperCase(r["descp"].ToString());  
                    //This checks to see if there is an alternate UOM i.e. CASES  
                    if ( r["utfum"].ToString() != string.Empty )  
                    {  
                        r["utmes"] = r["utfum"];  
                    }  
                }  
                // populate the list with the shopping cart contents  
                grid.DataSource = dt;  
                grid.DataBind();  
                // setup controls  
                titleLabel.Text = "These are the products in your shopping cart:";  
                grid.Visible = true;  
                updateButton.Enabled = true;  
                checkoutButton.Enabled = true;  
             }  
        }  
     
        protected void Page_PreRender( object sender, EventArgs e )  
        {  
     
            //Find a user-control in the master page  
            UserControl cartSummary = ( ( UserControl )Master.FindControl( "CartSummary1" ) );  
            //Update Cart Summary when updateButton is clicked  
              
            ram.AjaxSettings.AddAjaxSetting( updateButton, cartSummary );  
     
            //Ajax the entire grid  
            //RadAjaxManagerProxy1.AjaxSettings.AddAjaxSetting( grid, cartSummary );  
     
            #region old code  
            // dont need to do it for each row - just  
            //foreach ( GridViewRow row in grid.Rows )  
            //{  
            //    ImageButton deleteBtn = ( ( ImageButton )row.FindControl( "btnDelete" ) );  
            //    RadAjaxManagerProxy1.AjaxSettings.AddAjaxSetting( deleteBtn, cartSummary );  
     
            //}  
            #endregion  
     
     
        }  
     
          
     
        // remove a product from the cart  
        protected void deleteItemFromCart(object sender, GridViewDeleteEventArgs e)  
        {  
            // Index of the row being deleted  
            int rowIndex = e.RowIndex;  
            // The ID of the product being deleted  
            string productId = grid.DataKeys[rowIndex].Value.ToString();  
            // Remove the product from the shopping cart  
            bool success = ShoppingCartBAL.RemoveItem(productId);  
            // Display status  
            statusLabel.Text = success ? "<br />Product successfully removed from shopping cart!<br />" :  
                              "<br />There was an error removing the product from shopping cart!<br />";  
            // Repopulate the control  
            PopulateControls();  
        }  
     
        // update shopping cart product quantities  
        protected void updateCartItemQuantity(object sender, EventArgs e)  
        {  
            Page.Validate("cartQuantityValidationGroup");  
            if (Page.IsValid)  
            {  
                // Number of rows in the GridView  
                int rowsCount = grid.Rows.Count;  
                // Will store a row of the GridView  
                GridViewRow gridRow;  
                // Will reference a quantity TextBox in the GridView  
                TextBox quantityTextBox;  
                // Variables to store product ID and quantity  
                string productId;  
                int quantity;  
     
                // Was the update successful?  
                bool success = true;  
                // Go through the rows of the GridView  
                for (int i = 0; i < rowsCount; i++)  
                {  
                    // Get a row  
                    gridgridRow = grid.Rows[i];  
                    // The ID of the product being updated  
                    productId = grid.DataKeys[i].Value.ToString();  
                    // Get the quantity TextBox in the Row  
                    quantityTextBox = (TextBox)gridRow.FindControl("editQuantity");  
                    // Get the quantity, guarding against bogus values  
                    if (Int32.TryParse(quantityTextBox.Text, out quantity))  
                    {  
                        // Update product quantity  
                        successsuccess = success && ShoppingCartBAL.ShoppingCartUpdateItem(productId, quantity);  
                    }  
                    else  
                    {  
                        // if TryParse didn't succeed  
                        success = false;  
                    }  
                    // Display status message  
                    statusLabel.Text = success ?  
                      "<br />Your shopping cart was successfully updated!<br />" :  
                      "<br />Some quantity updates failed! Please verify your cart!<br />";  
                }  
     
                PopulateControls();  
            }  
        }  
     
        // Redirects to the previously visited catalog page   
        // (an alternate to the functionality implemented here is to    
        // Request.UrlReferrer, although that way you have no control to   
        // what pages you forward your visitor back to)  
        protected void continueShoppingButton_Click(object sender, EventArgs e)  
        {  
            // redirect to the last visited catalog page, or to the  
            // main page of the catalog  
            object page;  
            if ((page = Session["LastVisitedCatalogPage"]) != null)  
                Response.Redirect(page.ToString(), false);  
            else  
              //  Response.Redirect(Request.ApplicationPath);  
                Response.Redirect("../Homepage.aspx", false);  
        }  
     
        // create a new order and redirect to a payment page  
        protected void checkoutButton_Click(object sender, EventArgs e)  
        {  
             
            Response.Redirect("../MemberPages/CheckoutPage.aspx", false);  
        }  
        protected void grid_RowDataBound( object sender, GridViewRowEventArgs e )  
        {  
            if ( e.Row.RowType == DataControlRowType.DataRow )  
            {  
                totalhours += Convert.ToDecimal( DataBinder.Eval( e.Row.DataItem, "Subtotal" ) );  
            }  
            else if ( e.Row.RowType == DataControlRowType.Footer )  
            {  
                e.Row.Cells[4].Text = "Total Amount";  
                e.Row.Cells[5].Text = totalhours.ToString("c");  
                e.Row.Font.Bold = true;  
                e.Row.Cells[3].HorizontalAlign = HorizontalAlign.Right;  
            }  
        }  
        protected void grid_RowCreated( object sender, GridViewRowEventArgs e )  
        {  
            if( e.Row.RowType == DataControlRowType.DataRow )  
            {  
                e.Row.PreRender += new System.EventHandler( Row_PreRender );  
            }  
     
        }  
     
        protected void Row_PreRender( object sender, System.EventArgs e )  
        {  
            UserControl cartSummary = ( ( UserControl )Master.FindControl( "CartSummary1" ) );  
            TextBox txt = ( ( TextBox )( ( ( Control )( sender ) ).FindControl( "editQuantity" ) ) );  
            ImageButton ImageButton1 = ( ( ImageButton )( ( ( Control )( sender ) ).FindControl( "btnDelete" ) ) );  
            ram.AjaxSettings.AddAjaxSetting( txt, cartSummary );  
        }  
    }  
     
  11. John
    John avatar
    416 posts
    Member since:
    Oct 2006

    Posted 24 Sep 2007 Link to this post

    <hello />

    Thanks for the code. Unfortunately I still cannot reproduce the problem.

    Could you please check whether disabling AJAX (setting EnableAJAX property to false) avoids this problem?


    Thank you...
    <John:Peel />
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017