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

contextmenu and rowclick stops working on every other postback

1 Answer 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mabs
Top achievements
Rank 1
mabs asked on 26 Jul 2010, 12:12 PM
I have created a usercontrol for the grid.  I am having an issue where if you select a column to order by (click the heading), after the postbakc no rowclick, contextMenu and header contextMenu will work.  However if you sort again, they do.  So on every other postback the menu will work.

I have read on another forumk about adding the id of the contextMenu to the radajaxproxymanager, however the header contextMenu has no ID, also the rowclick also has no id as it is part of the grid.  My code is below,

<telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1" LoadingPanelID="progressLoader">
 
 
        <telerik:RadGrid ID="RadGrid1" 
                         runat="server"
                         GridLines="Vertical"                       
                         AllowSorting="true"
                         AllowPaging="true"
                         AllowCustomPaging="false"
                         AutoGenerateColumns="false"
                         EnableHeaderContextMenu="true"                       
                         Skin="Default"
                         PageSize="15"
                         OnNeedDataSource="RadGrid1_NeedDataSource"
             
                          >           
            <ExportSettings>
                <Pdf FontType="Subset" PaperSize="A4" />
                <Excel Format="Html" />
                <Csv ColumnDelimiter="Comma" RowDelimiter="NewLine" />
            </ExportSettings>
            <MasterTableView CommandItemDisplay="Top"  PagerStyle-AlwaysVisible="False"
                <PagerStyle Mode="NextPrevNumericAndAdvanced"></PagerStyle>         
               <CommandItemTemplate>
 
                      <asp:LinkButton ID="btn_save" runat="server" CommandName="saveGrid" ><asp:Image runat="server" ID="img_save" ImageUrl="~/_resources/images/icons/tick.png"/></asp:LinkButton>
                      <asp:LinkButton ID="btn_excel" runat="server" CommandName="excel" ><asp:Image runat="server" ID="Image1" ImageUrl="~/_resources/images/icons/xls_grey.gif"/></asp:LinkButton>                       
                     
                </CommandItemTemplate>
            </MasterTableView>
            <ClientSettings ReorderColumnsOnClient="True"
                            AllowDragToGroup="True"
                            AllowColumnsReorder="True"
                            EnablePostBackOnRowClick="False"
                            AllowGroupExpandCollapse="True" >
                            <Selecting AllowRowSelect="true" />
                             
                <Resizing AllowRowResize="True"
                          AllowColumnResize="True"
                          EnableRealTimeResize="True"
                          ResizeGridOnColumnResize="False">
                </Resizing>              
            </ClientSettings>
        </telerik:RadGrid>
 
</telerik:RadAjaxPanel>
Public Property Datasource() As DataTable
       Get
           Return _Datasource
       End Get
       Set(ByVal value As DataTable)
           _Datasource = value
       End Set
   End Property
 
   Public Property GridDataKeyNames() As String
       Get
           Return _GridDataKeyNames
       End Get
       Set(ByVal value As String)
           _GridDataKeyNames = value
       End Set
   End Property
 
   Public Property GridContextMenu() As Boolean
       Get
           Return _GridContextMenu
       End Get
       Set(ByVal value As Boolean)
           _GridContextMenu = value
       End Set
   End Property
 
   Public Property GridRowClick() As Boolean
       Get
           Return _GridRowClick
       End Get
       Set(ByVal value As Boolean)
           _GridRowClick = value
       End Set
   End Property
 
   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
       If Not IsPostBack Then          
           ViewState("gridData") = sectionCache
           ViewState("GridDataKeyNames") = GridDataKeyNames
           ViewState("GridContextMenu") = GridContextMenu
           ViewState("GridRowClick") = GridRowClick
       Else
           sectionCache = ViewState("gridData")
           GridDataKeyNames = ViewState("GridDataKeyNames")
           GridContextMenu = ViewState("GridContextMenu")
           GridRowClick = ViewState("GridRowClick")
       End If
 
       If Not Cache(sectionCache) Is Nothing Then
           Datasource = Cache(sectionCache)
       Else
           Cache(sectionCache) = Datasource
       End If
 
       standardGrid()
 
       If Not IsPostBack Then
 
           Dim hdn_field As HiddenField = TryCast(Page.Master.FindControl("hdn_pageId"), HiddenField)
 
           dataGrid = New DataRadGrid
           dataGrid.pageId = New Guid(hdn_field.Value.ToString())
           dataGrid.coreEntityId = Session.Item("RealId")
           Dim gridSettings As String = dataGrid.LoadSettings()
 
           If gridSettings <> "" Then
               Dim LoadPersister As New GridSettingsPersister(RadGrid1)
               LoadPersister.LoadSettings(gridSettings)
           End If
 
       End If
 
   End Sub
 
   Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
       RadGrid1.MasterTableView.VirtualItemCount = Datasource.Rows.Count
       RadGrid1.DataSource = Datasource
 
   End Sub
 
Protected Sub standardGrid()
 
       If GridRowClick Then
 
           If GridDataKeyNames = "" Then
               GridDataKeyNames = "ROWCLICK"
           Else
               GridDataKeyNames += ",ROWCLICK"
           End If
 
           RadGrid1.ClientSettings.ClientEvents.OnRowClick = "RowClick"
 
       End If
 
       If GridDataKeyNames <> "" Then
           Dim dataKeyNamesArray() As String = GridDataKeyNames.Split(",".ToArray())
 
           RadGrid1.MasterTableView.ClientDataKeyNames = dataKeyNamesArray
           RadGrid1.MasterTableView.DataKeyNames = dataKeyNamesArray
 
       End If
 
       If GridContextMenu Then
           RadGrid1.ClientSettings.ClientEvents.OnRowContextMenu = "RowContextMenu"
       End If
 
       Dim boundColumn As GridBoundColumn
 
       RadGrid1.MasterTableView.Columns.Clear()
 
       For Each column As DataColumn In Datasource.Columns
 
           If GridDataKeyNames <> "" Then
               If Not GridDataKeyNames.Contains(column.ColumnName.ToString()) Then
                   If column.ColumnName.ToString().IndexOf("_HIDDEN") < 0 Then
 
                       boundColumn = New GridBoundColumn
                       RadGrid1.MasterTableView.Columns.Add(boundColumn)
 
                       boundColumn.DataField = column.ColumnName
                       boundColumn.HeaderText = column.ColumnName.Replace("_", " ")
                       boundColumn.DataFormatString = "<nobr>{0}</nobr>"
                   Else
                       boundColumn = New GridBoundColumn
                       RadGrid1.MasterTableView.Columns.Add(boundColumn)
 
                       boundColumn.DataField = column.ColumnName
                       boundColumn.HeaderText = column.ColumnName
 
                       boundColumn.Visible = False
                   End If
 
               End If
           Else
               If column.ColumnName.ToString().IndexOf("_HIDDEN") < 0 Then
 
                   boundColumn = New GridBoundColumn
                   RadGrid1.MasterTableView.Columns.Add(boundColumn)
 
                   boundColumn.DataField = column.ColumnName
                   boundColumn.HeaderText = column.ColumnName.Replace("_", " ")
                   boundColumn.DataFormatString = "<nobr>{0}</nobr>"
               Else
                   boundColumn = New GridBoundColumn
                   RadGrid1.MasterTableView.Columns.Add(boundColumn)
 
                   boundColumn.DataField = column.ColumnName
                   boundColumn.HeaderText = column.ColumnName
 
                   boundColumn.Visible = False
               End If
           End If
 
 
       Next
 
   End Sub

Any help would be much appreciated

1 Answer, 1 is accepted

Sort by
0
mabs
Top achievements
Rank 1
answered on 26 Jul 2010, 12:45 PM
sorted, I had wrapped an ajaxPanel around the grid on userControl, was also using an radajaxmanager on the page calling the control.  Know that I have removed the ajaxPanel all is good.
Tags
Grid
Asked by
mabs
Top achievements
Rank 1
Answers by
mabs
Top achievements
Rank 1
Share this question
or