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
190
Server side Node Expanded Event needs 3 clicks to fire
posted

I have a web application project with Infragistics 2014.2 and .net Framework 4. In my web page I put a WebDataTree that is loaded only the first level of nodes. I need to get server side events every time a node is clicked or the node's expand button is clicked in order to decide programmatically if the child nodes need to be loaded.

This scenario works fine but the user needs to click three times the expand button to fire the server side event. This happened only when the node has no children loaded. If a node has children loaded the expand events working fine.

I created a small example showing this issue.

Default.aspx

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebDataTreeTest._Default" %>
<%@ Register Assembly="Infragistics4.Web.v14.2, Version=14.2.20142.2480, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" Namespace="Infragistics.Web.UI.NavigationControls" TagPrefix="ig" %>

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <ig:WebDataTree ID="WebDataTree1" runat="server" Height="600" Width="400px"
            CheckBoxMode="BiState" NodeIndent="18" EnableAjaxViewState="true"
            OnNodeClick="WebDataTree1_NodeClick" OnNodeExpanded="WebDataTree1_NodeExpanded">
            <AutoPostBackFlags NodeClick="On" NodeExpanded="On" />
        </ig:WebDataTree>
    </div>
    </form>
</body>
</html>

Default.aspx.vb

Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            For i As Integer = 1 To 5
                Dim tn As New Infragistics.Web.UI.NavigationControls.DataTreeNode()
                tn.Key = "1"
                tn.Value = "N|" & i.ToString()
                tn.Text = "Node" & i.ToString()
                tn.ToolTip = tn.Text
                tn.IsEmptyParent = True
                tn.Expanded = False
                WebDataTree1.Nodes.Add(tn)
            Next
        End If
    End Sub

    Protected Sub WebDataTree1_NodeClick(sender As Object, e As Infragistics.Web.UI.NavigationControls.DataTreeNodeClickEventArgs)
        If e.Node.HasChildren Then
            e.Node.Expanded = Not e.Node.Expanded
            Exit Sub
        End If
        AddNodes(e.Node)
        e.Node.Expanded = True
    End Sub

    Protected Sub WebDataTree1_NodeExpanded(sender As Object, e As Infragistics.Web.UI.NavigationControls.DataTreeNodeEventArgs)
        If e.Node.HasChildren Then
            Exit Sub
        End If
        AddNodes(e.Node)
        e.Node.Expanded = True
    End Sub

    Private Sub AddNodes(parentNode As Infragistics.Web.UI.NavigationControls.DataTreeNode)
        For i As Integer = 1 To 5
            Dim tn As New Infragistics.Web.UI.NavigationControls.DataTreeNode()
            tn.Key = CStr(Integer.Parse(parentNode.Key) + 1)
            tn.Value = "N|" & parentNode.Value.Split("|")(1) & i.ToString()
            tn.Text = "Node" & parentNode.Value.Split("|")(1) & i.ToString()
            tn.ToolTip = tn.Text
            tn.IsEmptyParent = True
            tn.Expanded = False
            parentNode.Nodes.Add(tn)
        Next
    End Sub

End Class

Parents Reply
  • 2671
    Offline posted in reply to Leo

    Hello,

    I only assumed you can use something that can be displayed from a client API (like a Dialog Window) and frankly I would strongly suggest a similar approach. There’s rarely anything that can’t be converted from server rendering to client interaction anyway. This also assumes you can easily render if event should be canceled and verified from a general server condition. The case becomes a bit more complicated if you need server validation for each node separately (and even that can be done through simple endpoint request).

    Cancelling the populating is easy enough:

    <ClientEvents NodePopulating="WebDataTree1_NodePopulating"/>

    <script type="text/javascript">

    function WebDataTree1_NodePopulating(tree, e) {

    e.set_cancel(true);

    //handle validation, use e.getNode() to get a reference to the node

    }

    To force postback after that you can call in the standard __doPostback(). This article has a good explanation how to pass in arguments so your backend: http://www.codeproject.com/Articles/667531/doPostBack-function and you will need something similar to set the node information to validate and handle the server side, as there will be no event to do that for you.

    Again I would only go through with the latter if the rest of the design is harder to change. I might be able to come up other solutions if you can provide a small sample with your general usage. Perhaps something other than manual load on demand can achieve the result you are looking for?

    Lastly, if you think having an interruptible and fully synchronous Load on Demand for the Data Tree is important, perhaps you would consider submitting it on our Feature Suggestions site at http://ideas.infragistics.com/forums/192360-asp-net - that can be very helpful when product management decides what to add next to the product.

    Regards,

    Damyan Petev

    Associate Software Developer

    Infragistics, Inc.

Children
No Data