Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
45
Using WARP inside a RowEditTemplate
posted

Hi All,

In the documentation it is recommended that fields in a row edit template be populated using javascript inside the BeforeRowTemplateOpenHandler client side event.   This is ok for simple scenarios, but a more powerful way to display the template would be to have a WARP panel in it that can be setup server side.  I have done this by calling a refresh on the warp during BeforeRowTemplateOpenHandler event.  I can populate controls and show and hide stuff and do whatever I want Big Smile ... However.... when saving the page (which also uses an async postback) there are extra rows added to the grid.  EG:  I add one row to the grid on the client and edit it using the RowEditTemplate with warp, and then on the server side there are 2 rows in the grid object.  I have no idea where the extra row is coming from....  turning off the warp inside the template makes the grid resume normal behaviour. 

From some other comments on these forums I understand that it may not be wise to do any server side interactions from within the rowedittemplate, so is what I am doing an outright bad idea?  If not, is there something I am doing wrong?

Regards,

Michael 

Parents
No Data
Reply
  • 45
    posted

    I have since realised that this is nothing to do with the RowEditTemplate.  To explain the issue more simply....

    Put a grid on a form.   (Enable adding rows on the client side with the add new box)

    Put a WARP on the same form.  Put a button in the middle of this warp to generate an async postback.

    In the pages PreRender event, output the number of rows in the grid object.

    Run the app.  Add a new row to the grid client side.

    Click the button in warp panel a few times.   Every time the async postback happens, another new row is added to the grid (of course you dont see the extra rows on the grid because it is not inside the warp so is not refreshed)

    Why does this happen?  Is it by design or a bug?

    I am using version 7.1.20071.1048

     

    Here is my code....

     

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridRowsIssue.aspx.cs" Inherits="GridRowsIssue" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Grid Rows Issue</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>Instructions:<br />
            <br />
            1/ Click Add New Row on the grid to add a new row client side.<br />
            2/ Click Do An Async Postback button a few times and watch output window to see
            how many rows the server thinks are in the grid.<br />
            3/ Notice that it is adding another row every time an async postback happens.<br /><br />
        </div>
        <igmisc:WebAsyncRefreshPanel ID="WARPGrid" runat="server" Width="100%" Display="Inline"
            TriggerControlIDs="btnSave">
            <igtbl:UltraWebGrid ID="uwgGrid" runat="server" Height="200px" Width="325px">
                <DisplayLayout Version="4.00" Name="UltraWebGrid1" AllowAddNewDefault="Yes" AllowDeleteDefault="Yes"
                    AllowUpdateDefault="Yes" RowHeightDefault="20px" TableLayout="Fixed" RowSelectorsDefault="No"
                    AllowColumnMovingDefault="OnServer" StationaryMargins="Header" BorderCollapseDefault="Separate"
                    StationaryMarginsOutlookGroupBy="True">
                    <AddNewBox Hidden="False">
                    </AddNewBox>
                </DisplayLayout>
            </igtbl:UltraWebGrid></igmisc:WebAsyncRefreshPanel>
        <div id="divRowEdit" style="display: block; z-index: 1000; position: absolute; width: 250px;
            height: 100px; top: 250px; background-color: #CCCCCC">
            <igmisc:WebAsyncRefreshPanel ID="WARPRowEditor" runat="server" Width="100%" Display="Inline"
                OnContentRefresh="WARPRowEditor_ContentRefresh">
                <asp:Button ID="btnAsyncPB" runat="server" Text="Do An Async Postback!" UseSubmitBehavior="False" />
            </igmisc:WebAsyncRefreshPanel>
        </div>
        </form>
    </body>
    </html>

     

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;


    public partial class GridRowsIssue : Page
    {
        DataTable myDataTable;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                System.Diagnostics.Debug.WriteLine("Initial Bind Of DataTable");

                myDataTable = new DataTable();

                myDataTable.Columns.Add("C1", typeof(string));
                myDataTable.Columns.Add("C2", typeof(string));

                myDataTable.Rows.Add(new object[ { "R1C1", "R1C2" });
                myDataTable.Rows.Add(new object[ { "R2C1", "R2C2" });

                Session["myDataTable"] = myDataTable;

                    uwgGrid.DataSource = myDataTable;
                    uwgGrid.DataBind();
            }
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            System.Diagnostics.Debug.WriteLine(String.Format("There are now {0} rows in the grid.",uwgGrid.Rows.Count.ToString()));
        }
        protected void WARPRowEditor_ContentRefresh(object sender, EventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("Warp has been refreshed at "+DateTime.Now.ToLongTimeString());
        }
    }
     

Children