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

Only RadScriptBlock works with multiple Proxies concurrently processed

3 Answers 134 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Saed
Top achievements
Rank 1
Saed asked on 04 May 2009, 08:33 AM
Hi there,
Something we observed today in this regard.

We have an aspx page mainly consists of UserControls: 4 loaded declaratively and one dynamically loaded into a PlaceHolder. The aspx page mimics a 'Master' page with the Place Holder functioning as the container of app. pages that are loaded via Menu. Before using your controls, there was an iFrame in place of current PlaceHolder where pages were loaded into. Thanks to your controls and smart approach, app. aspx pages are now being converted to UserControls and loaded dynamically into a single aspx.

Said aspx page has a RadScriptManager (replacing ASP ScriptManager), RadAjaxManager and RadAjaxLoadingPanel. Dynamically loaded UCs contain RadAjaxManagerProxies as advised in documentation. Things went fine with first converted UC especially after ajaxifying most of the tasks of code-behind, which drastically reduced overhead and improved performance. Due to the efficiency of RadAjaxManager, we dropped all ASP UpdatePanls that were encapsulating most of the controls.

When we converted our first aspx page into UC, we used RadCodeBlock to wrap JS code, which went fine. However, when we injected another Proxy into one of the 4 declaratively loaded UCs (Menu UC), JS blocks of converted UC no longer became recognised; always returns errors: function x not declared! Replacing Menu Proxy with code-behind declaration didn't help, even if it was accomplished in aspx code-behind!

After hours of experimenting, we figured out the solution. Replace RadCodeBlock with RadScriptBlock! For some reason, RadCodeBlock only works with a single UC that has a Proxy or linked to main RadAjaxManager. With multiple Proxy instances (one per UC) concurrently processed, RadCodeBlock fails to operate!

Is this popular? If so, how come none of your documentation mentioned it?

We are using latest release: Q1 2009, downloaded last week. Hope someone find this helpful...

Regards,

3 Answers, 1 is accepted

Sort by
0
Serrin
Top achievements
Rank 1
answered on 04 May 2009, 12:20 PM
Hello Saed,

With RadCodeBlock and RadScriptBlock, I found the following page to be helpful to sort of break down when to use each:

http://www.telerik.com/help/aspnet-ajax/ajxradscriptblockradcodeblock.html

One thing I immediately noticed is that RadScriptBlock is user "where you have Javascript that evaluates after an Ajax request", which sounds like it would be right up your alley since you are using RadAjaxManager and proxies.  It looks like they are used in slightly different situations, but if you're still running into errors when following the guidelines on that page, I think it might definitely help to post examples of the code you are running into problems with that way other community members can help look into the specific problems you are facing. :)


0
Saed
Top achievements
Rank 1
answered on 04 May 2009, 04:56 PM
Thanks Serrin for the link, but I've already seen it :-) but it wasn't much helpful to tell the truth.

In all the demos & documentation I have seen, RadCodeBlock is the prominent choice, so we used it without hesitation until we hit reported incident.

Sure I'll be happy to share our code although I doubt it might change situation. As I said, incident pops up when configuring more than one UC to utilise same RadAjaxManager.

Following is a summary of our situation.

Regards,
0
Saed
Top achievements
Rank 1
answered on 04 May 2009, 05:21 PM
Index.aspx
<%@ Page Language="VB" Debug="true" AutoEventWireup="false" CodeFile="index.aspx.vb" Inherits="TimeApp.Index" %> 
<%@ Register TagPrefix="ta" TagName="Banner" Src="~/Core/UC/topBanner.ascx" %> 
<%@ Register TagPrefix="ta" TagName="MainMenu" Src="~/Core/UC/globalMenu.ascx" %> 
<%@ Register TagPrefix="ta" TagName="SecMenu" Src="~/Core/UC/quickJump.ascx" %> 
<%@ Register TagPrefix="ta" TagName="Calendar" Src="~/Core/UC/qjCalendar.ascx" %> 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
 
<!-- --> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
   SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title></title
    <link href="Skins/Web20/ComboBox.Web20.css" rel="stylesheet" type="text/css" /> 
    <link href="Skins/Web20/TreeView.Web20.css" rel="stylesheet" type="text/css" /> 
    <link href="Skins/Web20/FormDecorator.Web20.css" rel="stylesheet" type="text/css" /> 
</head> 
<body> 
    <form id="taUI" runat="server"
        <telerik:RadScriptManager id="taRadScriptManager" runat="server" EnableTheming="True"
        </telerik:RadScriptManager> 
      
        <telerik:RadAjaxManager id="taRadAjaxManager" runat="server" UpdatePanelsRenderMode="Inline" RequestQueueSize="3" DefaultLoadingPanelID="taProcessPanel"
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="pageContent"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="pageContent" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
            </AjaxSettings> 
        </telerik:RadAjaxManager> 
 
        <telerik:RadFormDecorator id="taRadFormDecorator" runat="server" /> 
 
        <table id="InterfaceLayout" class="fullWindow" cellspacing="0" cellpadding="0"
            <tr> 
                <%-- Page Header --%> 
                <td id="Header" colspan="2"
                    <ta:Banner id="bannerUC" runat="server"></ta:Banner> 
                    <ta:MainMenu id="mainMenuUC" runat="server"></ta:MainMenu> 
                </td> 
            </tr> 
            <tr> 
                <%-- Quick Jump Navigation --%> 
                <td id="QuickJump"
                    <h1 class="qjHeader"><asp:Label id="qjTitle" runat="server"></asp:Label></h1
                    <ta:SecMenu id="qjMenuUC" runat="server"></ta:SecMenu> 
                    <ta:Calendar id="calendarUC" runat="server"></ta:Calendar> 
                </td>             
                <%-- Workspace --%>     
                <td id="Workplace"
                    <div class="posRel"
                        <telerik:RadAjaxLoadingPanel id="taProcessPanel" runat="server" IsSticky="true" MinDisplayTime="500" CssClass="progDialog"
                            <div class="progContent"
                                <asp:Literal runat="server" Text="<%$ Resources:General, dlg_Prog_Process %>"></asp:Literal> 
                            </div> 
                        </telerik:RadAjaxLoadingPanel>                     
                    </div>         
                    <asp:PlaceHolder id="pageContent" runat="server"></asp:PlaceHolder> 
                </td> 
            </tr> 
            <%-- Page Footer --%> 
            <tr> 
                <td id="Footer" colspan="2"><asp:Label id="Copyright" runat="server"></asp:Label></td
            </tr> 
        </table>     
    </form> 
</body> 
</html> 

Index.aspx.vb
Imports TimeApp.WebUtils 
'<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> 
Namespace TimeApp 
 
    Partial Class Index 
        Inherits taPage 
#Region "       Properties " 
 
        ' Store the last selected userControl for reload 
        Private Const CurrentControlKey As String = "CurrentControlKey" 
        Private Property CurrentControl() As String 
            Get 
                Return IIf(Me.ViewState(CurrentControlKey) Is Nothing, _ 
                           String.Empty, _ 
                           Me.ViewState(CurrentControlKey)) 
            End Get 
            Set(ByVal value As String
                Me.ViewState(CurrentControlKey) = value 
            End Set 
        End Property 
#End Region 
#Region "       Private Methods " 
 
        ' ***** Load UserControl into Page 
        Private Sub LoadUserControl(ByVal controlName As String
 
            ' Set the Path of UserControl to Load 
            Dim ucURL As String = AppSettings.pageRoot & controlName 
 
            ' Clear container PlaceHolder 
            pageContent.Controls.Clear() 
 
            ' Load UserControl into Page then Set its ID 
            Dim targetUC As UserControl = Page.LoadControl(ucURL) 
            targetUC.ID = GetControlID(controlName) 
 
            ' Add loaded UserControl to Content PlaceHolder 
            pageContent.Controls.Add(targetUC) 
 
            ' Save loaded UserControl into ViewState 
            Me.CurrentControl = controlName 
 
        End Sub 
 
        ' ***** Set ID of loaded UserControl 
        Private Function GetControlID(ByVal passedRef As StringAs String 
 
            Dim controlID As String = passedRef.Split("."c)(0) 
            Return "uc_" & controlID 
 
        End Function 
#End Region 
 
        '======================================================== 
#Region "           >> PAGE Handlers " 
 
        Protected Sub Page_Init(ByVal sender As ObjectByVal e As System.EventArgs) Handles MyBase.Init 
            If actUserID Is Nothing Then Response.Redirect("DenyAccess.aspx"
            InitialiseCSS() 
        End Sub 
 
        Protected Sub Page_Load(ByVal sender As ObjectByVal e As EventArgs) Handles MyBase.Load 
            Dim shortCutMenu As Menu = TryCast(qjMenuUC.FindControl("qjMenu"), Menu) 
            AddHandler shortCutMenu.MenuItemClick, AddressOf LoadSelected 
 
            taRadAjaxManager.AjaxSettings.AddAjaxSetting(shortCutMenu, shortCutMenu) 
            taRadAjaxManager.AjaxSettings.AddAjaxSetting(shortCutMenu, pageContent) 
 
            If (Not Me.CurrentControl Is String.Empty) Then 
                Me.LoadUserControl(Me.CurrentControl) 
            End If 
 
            SetPageTitle() 
            SetLabels() 
        End Sub 
#End Region 
        '======================================================== 
#Region "           >> Initialisation " 
 
        ' ***** Select CSS set 
        Private Sub InitialiseCSS() 
            '>> Identify culture-related set of CSS to use 
            '============================================= 
            Dim langRef, cssRoot, cssPath, cssName As String 
 
            ' Set default Root of CSS 
            cssRoot = "~/Styles/" 
 
            ' Set path of relivent CSS (Arabic or English) 
            langRef = Resources.General.loc_Locale_LangName 
            cssPath = cssRoot & langRef & "/" 
 
            ' Build CSS Links 
            Dim cssList() As String = {"Main""Layout""aspControls""otherControls"
            For cssIndex As Byte = 0 To cssList.GetUpperBound(0) 
 
                cssName = cssList(cssIndex) & ".css" 
                Dim cssHtmlLink As New HtmlLink() 
 
                cssHtmlLink.Href = ResolveUrl(cssPath & cssName) 
                cssHtmlLink.Attributes.Add("rel""stylesheet"
                cssHtmlLink.Attributes.Add("type""text/css"
 
                Page.Header.Controls.Add(cssHtmlLink) 
 
            Next cssIndex 
 
        End Sub 
 
        ' ***** Set Page Title 
        Private Sub SetPageTitle() 
            Dim pageTitle As String = "[" & Resources.General.app_Name & "]" 
            Me.Title = pageTitle 
        End Sub 
 
        ' ***** Define content of QuickJump Title & Footer 
        Private Sub SetLabels() 
            ' Qucik Jump Header 
            qjTitle.Text = Resources.General.app_qjTitle 
 
            ' Page Footer 
            Dim todayDate As Date = DateTime.Today() 
            Dim IS_Name, rights, thisYear As String 
            IS_Name = Resources.General.loc_Text_IS 
            rights = Resources.General.loc_Text_rightsRes 
            thisYear = " " & todayDate.Year & ". " 
            Copyright.Text = "&copy; " & IS_Name & Resources.General.loc_Text_Comma & thisYear & rights 
 
        End Sub 
#End Region 
        '======================================================== 
#Region "           >> Menu Manipulation " 
 
        ' ***** Load UserControl based on QuickJump Menu selection 
        Protected Sub LoadSelected(ByVal sender As ObjectByVal e As MenuEventArgs) 
 
            ' Get reference of UserControl to Load 
            Dim ucInfo() As String = e.Item.Value.Split(","
            Dim contentUC As String = ucInfo(0) 
 
            ' Store Page Title into Session 
            Session("pageTitle") = ucInfo(1) 
 
            ' Load UserControl 
            LoadUserControl(contentUC) 
 
        End Sub 
#End Region 
        '======================================================== 
 
    End Class 
 
End Namespace

*****************************************************************************************
quickJump.ascx
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="quickJump.ascx.vb" Inherits="TimeApp.quickJump" %> 
 
<div id="qjMenuWrapper"
    <asp:Menu  
        id="qjMenu"  
        runat="server"  
        Orientation="Vertical"   
        StaticMenuItemStyle-CssClass="aspMenuItem_Normal"  
        StaticSelectedStyle-CssClass="aspMenuItem_Selected" 
        StaticHoverStyle-CssClass="aspMenuItem_Hover"
    </asp:Menu> 
</div> 

quickJump.ascx.vb
Imports TimeApp.DBUtils 
'<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> 
Namespace TimeApp 
 
    Partial Class quickJump 
        Inherits System.Web.UI.UserControl 
 
        Protected newConn As Data.OleDb.OleDbConnection = DBConn.setOleDbConnection() 
 
        '======================================================== 
        '>> Page Handlers 
        '-------------------------------------------------------- 
        Protected Sub Page_Load(ByVal sender As ObjectByVal e As EventArgs) Handles MyBase.Load 
            buildQJMenu() 
        End Sub 
 
 
        '======================================================== 
        '>> Menu Manipulation 
        '-------------------------------------------------------- 
        ' ***** Construct Menu 
        Private Sub buildQJMenu() 
            Dim iconsDir As String = AppSettings.GetImgFolder(0) 
 
            ' Construct SQL Query 
            Dim sql As String = String.Empty 
            Dim actDesc As String = SetLocalised(0) 
            Dim infoFormat As String = "{0}.ascx,{1}" 
 
            sql = "SELECT item_id, " & actDesc & ", page, Icon FROM taMenu WHERE short_cut = Yes ORDER BY item_id" 
 
            ' Execute the Query 
            Dim qjData As New Data.DataTable() 
            qjData = FetchData(sql, newConn) 
 
            ' Populate the Menu 
            If qjData.Rows.Count > 0 Then 
 
                qjMenu.Items.Clear() 
 
                For Each row As Data.DataRow In qjData.Rows 
                    Dim Entry As MenuItem = New MenuItem() 
                    Entry.Text = row(actDesc) 
                    Entry.ImageUrl = iconsDir & row("Icon"
                    Entry.Value = String.Format(infoFormat, row("page"), row(actDesc)) 
 
                    ' Add the new Menu Entry 
                    qjMenu.Items.Add(Entry) 
                Next 
            Else    ' DataTable is Empty. Echo an ERROR message 
                MsgBox("Returned DataTable is EMPTY!", MsgBoxStyle.Critical, "ERROR ..."
            End If 
        End Sub 
 
 
    End Class 
 
End Namespace

*****************************************************************************************
codes.ascx (loaded at runtime)
<%@ Control Language="VB" Debug="true" AutoEventWireup="false" CodeFile="Codes.ascx.vb" Inherits="TimeApp.MainCodes" %> 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
<%@ Register TagPrefix="ta" TagName="actionBar" Src="~/Core/UC/actBar_4Btns.ascx" %> 
 
<telerik:RadAjaxManagerProxy id="taRadAjaxManagerProxy" runat="server"
    <AjaxSettings> 
        <telerik:AjaxSetting AjaxControlID="codesTV"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="codesTV" /> 
                <telerik:AjaxUpdatedControl ControlID="rcb_CodeCat" /> 
                <telerik:AjaxUpdatedControl ControlID="txt_CodeValue" /> 
                <telerik:AjaxUpdatedControl ControlID="txt_DescAlt" /> 
                <telerik:AjaxUpdatedControl ControlID="txt_DescEng" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
        <telerik:AjaxSetting AjaxControlID="ckb_ToggleState"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="codesTV" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
    </AjaxSettings> 
</telerik:RadAjaxManagerProxy> 
 
<telerik:RadScriptBlock id="ucRadScriptBlock" runat="server"
    <script language="javascript" type="text/javascript"
        var tree; 
        var catCombo; 
        var langFlag; 
        var nodeFlag; 
        var recFlag; 
        var codeValue; 
        var engDesc; 
        var altDesc; 
         
        function SetReference(sender, eventArgs) { 
            // Save a reference to the TreeView for later 
            tree = sender
        } 
 
        function GetObjects() { 
            catCombo = $find("<%= rcb_CodeCat.ClientID %>"); 
            langFlag = document.getElementById("<%= langFlag.ClientID %>"); 
            recFlag = document.getElementById("<%= recFlag.ClientID %>"); 
            codeValue = document.getElementById("<%= txt_CodeValue.ClientID %>"); 
            engDesc = document.getElementById("<%= txt_DescEng.ClientID %>"); 
            altDesc = document.getElementById("<%= txt_DescAlt.ClientID %>"); 
        } 
         
        function CastNodeInfo(sender, eventArgs) { 
            // 1. Get reference of relevant Controls to Cast to 
            GetObjects(); 
             
            // 2. Get selected Node, its Value & its Level 
            var currentNode = eventArgs.get_node(); 
            var nodeValue = currentNode.get_value(); 
            var nodeLevel = currentNode.get_level(); 
             
            if (nodeLevel == 0) { 
                // 2.1 Selected Node is RootNode: 
                //     2.1.1 Disable selection then Expand/Collapse; no Casting. 
                currentNode.set_postBack(false); 
                currentNode.unselect(); 
                currentNode.toggle(); 
 
                //     2.1.2 Restore selection of previously selected node 
                RestoreSelection(); 
                 
            } else { 
                // 2.2 Selected Node is ChildNode: 
                //     2.2.1 Get Node info stored in its Value property 
                 var nodeInfo = nodeValue.split(","); 
                 
                //     2.2.2 Cast CodeValue & Set its property 
                recFlag.value = "U"
                
                //     2.2.3 Set selection of ComboBox then Disable it  
                catCombo.trackChanges(); 
                var codeCat = catCombo.findItemByValue(nodeInfo[0]); 
                catCombo.enable(); 
                codeCat.select(); 
                catCombo.disable(); 
                catCombo.commitChanges(); 
 
                //     2.2.4 Cast CodeValue & Set its property 
                codeValue.value = nodeInfo[1]; 
                codeValue.readOnly = true
 
                //     2.2.5 Cast remaining Node info to related TextBoxes 
                var actLang = langFlag.value; 
                var actDesc = currentNode.get_text().substring(4); 
                if (actLang == "eng") { 
                    engDesc.value = actDesc
                    altDesc.value = nodeInfo[2]; 
                } else { 
                    engDesc.value = nodeInfo[2]; 
                    altDesc.value = actDesc
                } 
 
                //     2.2.6 Save current Node value for later restoration 
                nodeFlag = document.getElementById("<%= nodeFlag.ClientID %>"); 
                nodeFlag.value = nodeValue
            } 
        } 
 
        function ResetFields() { 
            // 1. Get reference of relivent Controls to handle 
            GetObjects(); 
 
            // 2. Reset status/proprties of retrieved Controls 
            recFlag.value = "N"
 
            var selectedNode = tree.get_selectedNode(); 
            if (selectedNode != null) { 
                selectedNode.select(); 
            } 
             
            catCombo.enable(); 
            catCombo.clearSelection(); 
 
            codeValue.value = ""
            codeValue.readOnly = false
            engDesc.value = ""
            altDesc.value = ""
        } 
 
        function RestoreSelection() { 
            nodeFlag = document.getElementById("<%= nodeFlag.ClientID %>"); 
            var wasSelected = tree.findNodeByValue(nodeFlag.value); 
            if (wasSelected != null) { 
                wasSelected.select(); 
            } 
        } 
    </script> 
</telerik:RadScriptBlock> 
 
<table id="main" cellspacing="0" cellpadding="0"
    <tr> 
        <td id="titleWrapper"
            <%-- PAGE TITLE --%> 
            <h1><asp:Label id="contentTitle" runat="server"></asp:Label></h1
        </td> 
    </tr> 
    <tr> 
        <td class="fullWindow"
            <table id="workplaceLayout" cellspacing="8" cellpadding="0"
                <tr> 
                    <td id="tvPane" rowspan="2"
                        <table class="fullHeight" cellspacing="0" cellpadding="0"
                            <tr> 
                                <td id="tvTitle"
                                    <%-- TREE VIEW TITLE --%> 
                                    <h2><asp:Label runat="server" Text="<%$ Resources:DataValues, tv01_Codes %>"></asp:Label></h2
                                </td> 
                            </tr> 
                            <tr> 
                                <td class="fullHeight"
                                     <%-- TREE VIEW BODY --%> 
                                    <div id="tvWrapper"
                                        <telerik:RadTreeView id="codesTV" runat="server" OnClientLoad="SetReference" OnClientNodeClicked="CastNodeInfo"></telerik:RadTreeView> 
                                    </div>             
                                </td> 
                            </tr> 
                        </table> 
                    </td> 
                    <td id="contentPane"
                        <%-- CONTENT --%> 
                        <div id="contentWrapper" class="padded0515"
                            <asp:HiddenField id="langFlag" runat="server" /> 
                            <asp:HiddenField id="nodeFlag" runat="server" /> 
                            <asp:HiddenField id="recFlag" runat="server" /> 
                            <table class="objBlock" cellpadding="0" cellspacing="0"
                                <tr> 
                                    <td class="adjuster"><asp:Image runat="server" ImageUrl="~/images/layout/spacer.gif" CssClass="width015" /></td
                                    <td class="adjuster autoWidth">&nbsp;</td> 
                                    <td class="adjuster">&nbsp;</td> 
                                    <td class="adjuster fullWidth">&nbsp;</td> 
                                    <td class="adjuster"><asp:Image runat="server" ImageUrl="~/images/layout/spacer.gif" CssClass="width015" /></td
                                </tr> 
                                <tr><td colspan="5" class="vSpacer10"><div class="blockTitle"><asp:Literal runat="server" Text="<%$ Resources:LabelNames, cod00_BlockTitle_Master %>"></asp:Literal></div></td></tr
                                <tr><td colspan="5" class="hFrameTop">&nbsp;</td></tr>                             
                                <tr> 
                                    <td rowspan="5" class="vFrameLeft">&nbsp;</td> 
                                    <th><asp:Label runat="server" Text="<%$ Resources:LabelNames, cod01_CodeCat %>"></asp:Label></th
                                    <td> 
                                        <telerik:RadComboBox id="rcb_CodeCat" runat="server" Width="150px" DropDownWidth="150px"></telerik:RadComboBox> 
                                    </td> 
                                    <td rowspan="5">&nbsp;</td> 
                                    <td rowspan="5" class="vFrameRight">&nbsp;</td> 
                                </tr> 
                                <tr> 
                                    <th><asp:Label runat="server" Text="<%$ Resources:LabelNames, cod02_CodeValue %>"></asp:Label></th
                                    <td><asp:TextBox id="txt_CodeValue" runat="server" CssClass="aspTextBox width060 centered"></asp:TextBox></td
                                </tr> 
                                <tr> 
                                    <th class="altAlign"><asp:Label runat="server" Text="<%$ Resources:LabelNames, cod03_DescALT %>"></asp:Label></th
                                    <td><asp:TextBox id="txt_DescAlt" runat="server" CssClass="aspTextBox width320 rtlStyle"></asp:TextBox></td
                                </tr> 
                                <tr> 
                                    <th class="altAlign"><asp:Label runat="server" Text="<%$ Resources:LabelNames, cod04_DescENG %>"></asp:Label></th
                                    <td><asp:TextBox id="txt_DescEng" runat="server" CssClass="aspTextBox width320 ltrStyle"></asp:TextBox></td
                                </tr> 
                                <tr><td colspan="2" class="vSpacer10">&nbsp;</td></tr>                             
                                <tr><td colspan="5" class="hFrameBtm">&nbsp;</td></tr>                             
                                <tr><td colspan="5" style="padding-top: 10px"><asp:CheckBox id="ckb_ToggleState" runat="server" AutoPostBack="true" CssClass="aspCheckBox"/><asp:Label runat="server" Text="<%$ Resources:LabelNames, cod05_ExpColl %>"></asp:Label></td
                                </tr>                     
                            </table>             
                        </div>                     
                    </td> 
                </tr> 
                <tr> 
                    <td id="actionPane"
                        <%-- ACTION BAR --%> 
                        <ta:actionBar id="actBar_4Buttons" runat="server"></ta:actionBar> 
                    </td> 
                </tr> 
            </table> 
        </td> 
    </tr>     
</table> 

codes.ascx.vb
Imports System.Data 
Imports TimeApp.DBUtils 
Imports TimeApp.WebUtils 
Imports Telerik.Web.UI 
'<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> 
Namespace TimeApp 
 
    Partial Class MainCodes 
        Inherits System.Web.UI.UserControl 
#Region "   Variables Declaration " 
 
        Protected conn As Data.OleDb.OleDbConnection = DBConn.setOleDbConnection() 
        Private actDesc As String = SetLocalised(0) 
        Private Shared codesData As New DataTable() 
        Private altDesc As String = "description_alt" 
#End Region 
 
        '======================================================== 
#Region "           >> PAGE Handlers " 
 
        Protected Sub Page_Init(ByVal sender As ObjectByVal e As EventArgs) Handles MyBase.Init 
 
            contentTitle.Text = Session("pageTitle")                        ' Get Page Title 
            langFlag.Value = Resources.General.loc_Locale_LangCode          ' Save active Locale 
            If WebUtils.actUserLangID <> 1 Then altDesc = "description_eng" ' Set Alt. Locale 
 
        End Sub 
 
        Protected Sub Page_Load(ByVal sender As ObjectByVal e As EventArgs) Handles MyBase.Load 
 
            GetData() 
            FillDrops() 
            GenerateMajors() 
            recFlag.Value = "N" 
 
            Dim btnNew As Button = TryCast(actBar_4Buttons.FindControl("btn_New"), Button) 
            btnNew.Attributes.Add("onClick""ResetFields();"
 
        End Sub 
 
        Protected Sub Page_Unload(ByVal sender As ObjectByVal e As EventArgs) Handles MyBase.Unload 
 
        End Sub 
#End Region 
        '======================================================== 
#Region "           >> Initialisation " 
 
        Private Sub GetData() 
            Dim sql As String = String.Empty 
 
            sql = "SELECT maj_id, min_id, description_eng, description_alt FROM t_Codes " 
            sql &= "ORDER BY maj_id, min_id" 
            codesData = FetchData(sql, conn) 
 
        End Sub 
#End Region 
        '======================================================== 
#Region "           >> ComboBox Manipulation " 
 
        ' ***** Fill Code Category DropDownList 
        Private Sub FillDrops() 
 
            Dim majorCodes As DataView = New DataView(codesData, _ 
                                                      "min_id = 0""maj_id", _ 
                                                      DataViewRowState.OriginalRows) 
            rcb_CodeCat.DataTextField = actDesc 
            rcb_CodeCat.DataValueField = "maj_id" 
            rcb_CodeCat.DataSource = majorCodes 
 
            rcb_CodeCat.DataBind() 
 
            FillBlank(rcb_CodeCat) 
 
        End Sub 
 
        Private Sub FillBlank(ByVal passedRCB As RadComboBox) 
            Dim blankItem As New RadComboBoxItem() 
            blankItem.Text = String.Empty 
            blankItem.Value = 0 
 
            passedRCB.Items.Insert(0, blankItem) 
        End Sub 
#End Region 
        '======================================================== 
#Region "           >> TreeView Manipulation " 
 
        ' ***** Populate LEVEL 0 Nodes (CodeCategories) 
        Private Sub GenerateMajors() 
 
            If codesTV.Nodes.Count > 0 Then codesTV.Nodes.Clear() 
 
            Dim nodeID As UInt32 
            Dim nodeFocus As String = "maj_id" 
            Dim imgBase As String = AppSettings.GetImgFolder()(1) 
            Dim infoFormat As String = "{0:D2}- {1}" 
 
            Dim majorCodes As DataView = New DataView(codesData, _ 
                                                      "min_id = 0", _ 
                                                      "maj_id", _ 
                                                      DataViewRowState.OriginalRows) 
 
            For Each majorCode As DataRowView In majorCodes 
 
                nodeID = majorCode(nodeFocus) 
                Dim majorNode As RadTreeNode = New RadTreeNode() 
 
                majorNode.Text = String.Format(infoFormat, nodeID, majorCode(actDesc)) 
                majorNode.Value = nodeID 
                majorNode.ImageUrl = imgBase & "Codes_L0.png" 
 
                majorNode.PostBack = False 
                majorNode.Selected = False 
                majorNode.ExpandMode = TreeNodeExpandMode.ServerSideCallBack 
 
                codesTV.Nodes.Add(majorNode) 
 
            Next majorCode 
 
         End Sub 
 
        ' ***** PopulateOnDemand LEVEL 1 Nodes (CodeValues) 
        Protected Sub PopulateOnDemand(ByVal sender As ObjectByVal e As RadTreeNodeEventArgs) Handles codesTV.NodeExpand 
 
            Dim nodeID As UInt32 
            Dim nodeFocus As String = "min_id" 
            Dim imgBase As String = AppSettings.GetImgFolder()(1) 
            Dim infoFormat As String = "{0:D2}- {1}" 
 
            Dim parentID As UInt32 = Convert.ToUInt32(e.Node.Value) 
 
            Dim minorCodes As DataView = New DataView(codesData, _ 
                                                      "maj_id = " & parentID & " AND min_id > 0", _ 
                                                      "min_id", _ 
                                                      DataViewRowState.OriginalRows) 
 
            For Each minorCode As DataRowView In minorCodes 
 
                Dim minorNode As RadTreeNode = New RadTreeNode() 
 
                nodeID = minorCode(nodeFocus) 
                minorNode.Text = String.Format(infoFormat, nodeID, minorCode(actDesc)) 
                minorNode.Value = parentID & "," & nodeID & "," & minorCode(altDesc) 
                minorNode.ImageUrl = imgBase & "Codes_L1.png" 
 
                e.Node.Nodes.Add(minorNode) 
 
                e.Node.ExpandMode = TreeNodeExpandMode.ClientSide 
                e.Node.Expanded = True 
 
            Next minorCode 
 
        End Sub 
 
        ' ***** Populate LEVEL 1 Nodes (required when Expanding All Nodes at once) 
        Private Sub PopulateMinors(ByVal nodesData As DataView, ByVal parentNode As RadTreeNode) 
            Dim nodeFocus As String = "min_id" 
            Dim imgBase As String = AppSettings.GetImgFolder()(1) 
            Dim infoFormat As String = "{0:D2}- {1}" 
 
            For Each minorCode As DataRowView In nodesData 
 
                Dim minorNode As RadTreeNode = New RadTreeNode() 
 
                minorNode.Text = String.Format(infoFormat, minorCode(nodeFocus), minorCode(actDesc)) 
                minorNode.Value = parentNode.Value & "," & minorCode(nodeFocus) 
                minorNode.ImageUrl = imgBase & "Codes_L1.png" 
 
                parentNode.Nodes.Add(minorNode) 
 
                parentNode.ExpandMode = TreeNodeExpandMode.ClientSide 
                parentNode.Expanded = True 
 
            Next minorCode 
        End Sub 
#End Region 
        '======================================================== 
#Region "           >> Other Controls " 
 
        ' ***** Expand/Collapse TreeView 
        Protected Sub ToggleExpantion(ByVal sender As ObjectByVal e As EventArgs) Handles ckb_ToggleState.CheckedChanged 
            Try 
                Dim trigger As CheckBox = TryCast(sender, CheckBox) 
 
                If codesTV.SelectedValue IsNot Nothing _ 
                Then nodeFlag.Value = codesTV.SelectedValue 
 
                If trigger.Checked Then 
                    ' Populate ChildNodes then Expand All 
                    For Each catNode As RadTreeNode In codesTV.Nodes() 
 
                        If Not catNode.Expanded Then 
                            Dim minorCodes As DataView = New DataView(codesData, _ 
                                                                      "maj_id = " & catNode.Value & " AND min_id > 0", _ 
                                                                      "min_id", _ 
                                                                      DataViewRowState.OriginalRows) 
                            PopulateMinors(minorCodes, catNode) 
                        End If 
 
                    Next catNode 
 
                    If nodeFlag.Value IsNot String.Empty Then 
                        Dim wasSelected As RadTreeNode = codesTV.FindNodeByValue(nodeFlag.Value) 
                        wasSelected.Selected = True 
                    End If 
 
                Else 
                    ' Collapse All 
                    codesTV.CollapseAllNodes() 
                End If 
 
            Catch ex As Exception 
                MsgBox("Error in Tree Toggle Expantion..." & vbCrLf & vbCrLf & GetMsgInfo(50)(0) & " [" & ex.Message & "]", MsgBoxStyle.Exclamation, GetMsgInfo(50)(1)) 
            End Try 
 
        End Sub 
#End Region 
        '======================================================== 
#Region "           >> Data Manipulation " 
 
...
#End Region 
        '======================================================== 
 
 
    End Class 
 
End Namespace


Hope this helps.

Regards,
Tags
Ajax
Asked by
Saed
Top achievements
Rank 1
Answers by
Serrin
Top achievements
Rank 1
Saed
Top achievements
Rank 1
Share this question
or