RadDock AutoPostBack clears client-side databound RadGrids

2 posts, 0 answers
  1. Josh
    Josh avatar
    5 posts
    Member since:
    Aug 2011

    Posted 26 Aug 2011 Link to this post

    I understand why this is happening, but I'm not sure the best way to handle it.  The postback created when a RadDock is drag & dropped, closed, minimized, etc. is returning the HTML and overwriting the data bound RadGrids that are in the RadDocks within the RadDockZone that the RadDock is in.  I don't want to requery the the web methods to repopulate the grids (kinda defeats the benefit of client-side data binding).

    I have AutoPostBack enabled on the docks because I want to continuously persist the position/state of the docks.  Is there anyway I can update the state of the docks via AJAX without doing a partial postback that overwrites my grid data (maybe by calling a WebMethod)?  If so, how?

    I've created a simple example page that demonstrates this issue (most controls are dynamically created because this is how the real application is).


    Imports Telerik.Web.UI
    Imports System.Web.UI.WebControls
    Partial Class DockClientDataBoundRadGrid
        Inherits System.Web.UI.Page
        Private _DockDataTable As System.Data.DataTable
        Protected Sub RadDockLayout1_LoadDockLayout(ByVal sender As Object, ByVal e As Telerik.Web.UI.DockLayoutEventArgs) Handles RadDockLayout1.LoadDockLayout
            Dim zones(1) As RadDockZone
            Dim zone As RadDockZone
            For i As Integer = 0 To zones.Length - 1
                zone = New RadDockZone
                zone.Orientation = Orientation.Vertical
                zone.ID = "RadDockZone" & i
                zones(i) = zone
            For Each zone In zones
                RadAjaxManager1.AjaxSettings.AddAjaxSetting(zone, zone)
            Dim docks(DockDataTable.Rows.Count - 1) As RadDock
            Dim dock As RadDock
            Dim rowCount As Integer = 0
            For Each row As System.Data.DataRow In DockDataTable.Rows
                dock = New RadDock
                dock.AutoPostBack = True
                dock.DockMode = DockMode.Docked
                dock.UniqueName = "dock-" & rowCount
                dock.Title = row.Item("title")
                Dim _RadGrid As RadGrid = CreateRadGrid("RadGrid-" & rowCount)
                docks(rowCount) = dock
                rowCount += 1
                RadAjaxManager1.AjaxSettings.AddAjaxSetting(dock.ContentContainer, dock.ContentContainer)
            Dim lastZoneId As Integer = 0
            For Each dock In docks
                If zones.Length <= lastZoneId Then lastZoneId = 0
                zone = zones(lastZoneId)
                e.Indices(dock.UniqueName) = zone.Docks.Count
                e.Positions(dock.UniqueName) = zone.ID
                lastZoneId += 1
        End Sub
        Private Function CreateRadGrid(ByVal ControlID As String) As RadGrid
            Dim _RadGrid As New RadGrid
            _RadGrid.ID = ControlID
            _RadGrid.ClientSettings.ClientEvents.OnCommand = "RadGrid1_DataBinding"
            _RadGrid.ClientSettings.DataBinding.Location = "~/DockClientDataBoundRadGrid.aspx"
            _RadGrid.ClientSettings.DataBinding.SelectMethod = "GetData"
            _RadGrid.ClientSettings.DataBinding.SelectCountMethod = "GetDataCount"
            _RadGrid.ClientSettings.DataBinding.StartRowIndexParameterName = "startRowIndex"
            _RadGrid.ClientSettings.DataBinding.MaximumRowsParameterName = "maxRows"
            _RadGrid.ClientSettings.DataBinding.EnableCaching = True
            _RadGrid.PageSize = 10
            Dim c1 As New GridBoundColumn
            c1.HeaderText = "Name"
            c1.SortExpression = "Name"
            c1.DataField = "Name"
            c1.UniqueName = "Name"
            c1.DataType = System.Type.GetType("System.String")
            Return _RadGrid
        End Function
        Protected Function CreateDockContainer(ByRef zones As Telerik.Web.UI.RadDockZone()) As System.Web.UI.WebControls.WebControl
            Dim tbl As System.Web.UI.WebControls.Table = New System.Web.UI.WebControls.Table
            tbl.ID = "tblDockContainer"
            tbl.Style.Add("width", "100%")
            Dim row As System.Web.UI.WebControls.TableRow = New System.Web.UI.WebControls.TableRow
            Dim cell As System.Web.UI.WebControls.TableCell
            Dim colSize As String = Math.Floor(100 / zones.Length).ToString() & "%"
            For Each zone As Telerik.Web.UI.RadDockZone In zones
                cell = New System.Web.UI.WebControls.TableCell
                cell.VerticalAlign = VerticalAlign.Top
                cell.Style.Add("width", colSize)
            Return tbl
        End Function
        Protected ReadOnly Property DockDataTable() As System.Data.DataTable
                If _DockDataTable Is Nothing Then
                    _DockDataTable = New System.Data.DataTable
                    _DockDataTable.Columns.Add(New System.Data.DataColumn("title", System.Type.GetType("System.String")))
                    Dim row As System.Data.DataRow
                    For i As Integer = 0 To 5
                        row = _DockDataTable.NewRow
                        row("title") = "Dock Title " & i
                End If
                Return _DockDataTable
            End Get
        End Property
        <System.Web.Services.WebMethod()> _
        Public Shared Function GetData(ByVal startRowIndex As Integer, ByVal maxRows As Integer) As IEnumerable
            Dim list As New Generic.List(Of Entity)
            For i As Integer = startRowIndex To maxRows
                Dim e As New Entity
                e.Name = "Entity " & i
            Return list
        End Function
        <System.Web.Services.WebMethod()> _
        Public Shared Function GetDataCount() As Integer
            Return 51
        End Function
        Public Class Entity
            Public Name As String
        End Class
    End Class

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="DockClientDataBoundRadGrid.aspx.vb" Inherits="DockClientDataBoundRadGrid" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"></telerik:RadAjaxManager>
    <telerik:RadDockLayout ID="RadDockLayout1" runat="server"></telerik:RadDockLayout>
    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
        <script type="text/javascript">
            function RadGrid1_DataBinding(sender, args) {}   
  2. Josh
    Josh avatar
    5 posts
    Member since:
    Aug 2011

    Posted 26 Aug 2011 Link to this post

    Okay, this was a dumb mistake on my part, I believe.  When the postback occured in a RadDockZone, the RadAjaxManager set the zone as the control to update.  I don't believe this was necessary, so I can just set it to something else and it'll still pass along the new positions and indicies of the docks.  I do wish the response wasn't so large.  It was 27KB for a dockpositionchanged postback.
Back to Top