TreeView Node Object Reference error when use with Context Menu

2 posts, 0 answers
  1. Sri
    Sri avatar
    22 posts
    Member since:
    Jun 2009

    Posted 07 Oct 2009 Link to this post

    Hello,

    We are using Telerik Controls Version 2009.2.826.20 in our application and we are experiencing difficulties with RAD TreeView Node in the Context Menu Item.

    Below is the set of RAD Controls we are using in the Application:
    1. Toolbar control. (This renders the functioanlity very fine)
    2. RAD Splitter Control.
    3. Left Pane we got RAD TreeView Control. (Implement Load on Demand using Page Behind Method)
    4. Right Pane we got sub Panels using DIV Controls. We are show/hide the Div's depending on the items selected in the Context Menu of the Tree View Control.

    When we run the application, we are able to expand or collapse the Nodes. When the User right click a Node and select an item from the Context Menu, the event for the Context menu throws Object Reference Error. Sometimes it works and some times it doesnt work.

    Why is the behavior as such? Can you help us to resolve this issue?

    Below is the Code we have in our application for the Context Menu Item Event:
    (We are accessing the node using e.Node and if the e.Node is present it works. In so many cases e.Node is becoming NULL and this is giving us the error Object Reference not set to an instance of an Object)
    (The application works if we use the button from the ToolBar. Because in ToolBar event, we are accessing the Node using SelectedNode property and that works)

        Protected Sub RdTViewPerspective_ContextMenuItemClick(ByVal sender As System.Object, ByVal e As Telerik.Web.UI.RadTreeViewContextMenuEventArgs) Handles RdTViewPerspective.ContextMenuItemClick
            Try
                Select Case e.MenuItem.Value.ToUpper()
                    Case "SAP_INFO"
                        HideAllPanels()
                        DisplayGeneralInformation(e.Node)
                        DisplaySAPInfoPanel(e.Node)
                        ReSetToolBarButtons(e.Node)
                    Case Else
                        'Nothing to do.
                End Select
            Catch ex As Exception
                log.Info(ex.Message.ToString())
                Response.Redirect("CustomError.aspx?Msg=" + Server.UrlEncode(ex.Message.ToString()) + "&ErrorSource=" + Server.UrlEncode(ex.Source.Replace(Environment.NewLine, "-----><BR>").ToString()) + "&ErrorStack=" + Server.UrlEncode(ex.StackTrace.ToString()), False)
            End Try
        End Sub


    Thanks
    Sri K Gamini.
  2. Sri
    Sri avatar
    22 posts
    Member since:
    Jun 2009

    Posted 07 Oct 2009 Link to this post

    An addition to the above Post.

    When the User right click on a Tree Node, and select an item, the Node is becoming NULL in the event handler method and the same node we are not able to access using the Toolbar too.
    Earlier I reported that we can access it from Toolbar. But it is wrong. We are not able to access that Node either from Context Menu or Toolbar.

    We changed the code as below and we observed that the Tree is loosing Nodes:

        Protected Sub RdTViewPerspective_ContextMenuItemClick(ByVal sender As System.Object, ByVal e As Telerik.Web.UI.RadTreeViewContextMenuEventArgs) Handles RdTViewPerspective.ContextMenuItemClick
            Try

                'Tree Node Validation:
                If e.Node Is Nothing Then
                    RadAjaxManager1.Alert("Unable to perform the Action! Tree Node is NULL.\nPlease try your request again!\nWe are sorry for any inconvenience this may have caused you.")
                    Exit Sub
                End If

                Select Case e.MenuItem.Value.ToUpper()
                    Case "SAP_INFO"
                        HideAllPanels()
                        DisplayGeneralInformation(e.Node)
                        DisplaySAPInfoPanel(e.Node)
                        ReSetToolBarButtons(e.Node)
                    Case Else
                        'Nothing to do.
                End Select
            Catch ex As Exception
                log.Info(ex.Message.ToString())
                Response.Redirect("CustomError.aspx?Msg=" + Server.UrlEncode(ex.Message.ToString()) + "&ErrorSource=" + Server.UrlEncode(ex.Source.Replace(Environment.NewLine, "-----><BR>").ToString()) + "&ErrorStack=" + Server.UrlEncode(ex.StackTrace.ToString()), False)
            End Try
        End Sub


    When the Node becomes NULL, we see the error message populate on the screen and immediately some of the Tree Nodes disapears from the Tree. Means if we are at the six or seventh level in the hierarhcy, the tree looses till 3rd level or 4th level.

    Why is it so? Can you help us?

    See the attached screen shots!!

    Thanks
    Sri K Gamini.
Back to Top