Using Delegates with RadMenu and UserControls

I have an ASP.NET project that has a form that uses a user control/RadMenu for the menu. I need the menu to raise an event on the parent form, so that the parent form can load data. I've coded this in Winform controls, but never ASP.NET, so... here the example.

Here's the user control

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="ProjectMenu.ascx.vb" Inherits="CRM.ProjectMenu" %>
    <table>
        <tr>
            <td>
                <asp:Label runat="server" ID="lblError" CssClass="Error"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                <telerik:RadMenu ID="RadMenu1" runat="server" Skin="Bootstrap" RenderMode="Lightweight" Flow="Horizontal" CssClass="DarkBlueMenu">
                    <Items>
                        <telerik:RadMenuItem  Text="BIDDING" Value="BIDDING"  />
                        <telerik:RadMenuItem Text="WON/LOST" VALUE="WON/LOST"  />
                    </Items>
                </telerik:RadMenu>
            </td>
        </tr>
    </table>
Imports Telerik.Web.UI
 
Public Class ProjectMenu
    Inherits InheritedUserControl
 
    Public Event ProjectMenu_MenuSelectionMade As EventHandler(Of RadMenuEventArgs)
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'code that selects the correct tab of the menu.
        'css is applied to change the color
        Dim current As RadMenuItem = RadMenu1.FindItemByUrl(Request.Url.AbsolutePath)
        If current IsNot Nothing Then
            current.Selected = True
        End If
    End Sub
 
    Private Sub RadMenu1_ItemClick(sender As Object, e As RadMenuEventArgs) Handles RadMenu1.ItemClick
        Dim strError As String = ""
 
        Try
            'raise the event to the parent form
            RaiseEvent ProjectMenu_MenuSelectionMade(Me, e)
        Catch ex As Threading.ThreadAbortException
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, App.AppName, App.UserName, False)
            Me.lblError.Text = ex.Message
        End Try
 
    End Sub
 
 
End Class

 

This is the containing form

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site1.Master" CodeBehind="ProjectSummary.aspx.vb" Inherits="CRM.ProjectSummary" %>
 
<%@ Register Src="~/UserControls/ProjectMenu.ascx" TagPrefix="uc1" TagName="ProjectMenu" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="CSS/DarkBlueMenu.css" rel="stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <uc1:ProjectMenu runat="server" ID="ProjectMenu" />
 
    <div class="layout">
        <div class="content-area">
            <asp:Label runat="server" ID="lblError" CssClass="Error"></asp:Label>
            <asp:PlaceHolder ID="PlaceHolder1" runat="server" />
        </div>
    </div>
 
</asp:Content>

 

Imports Telerik.Web.UI
 
Public Class ProjectSummary
    Inherits InheritedPage
 
    Private Sub ProjectSummary_Init(sender As Object, e As EventArgs) Handles Me.Init
        Dim strError As String = ""
 
        Try
            'register for the event from the user control
            AddHandler ProjectMenu.ProjectMenu_MenuSelectionMade, AddressOf MenuSelectionMade
 
        Catch ex As Threading.ThreadAbortException
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, App.AppName, App.UserName, False)
            Me.lblError.Text = ex.Message
        End Try
 
    End Sub
 
    Private Sub MenuSelectionMade(sender As Object, e As RadMenuEventArgs)
        Dim strError As String = ""
 
        Try
            'handle the event
            Select Case e.Item.Value.ToUpper
                Case "BIDDING"
                    LoadControlIntoPanel("~/UserControls/ProjectSummaryBidding.ascx")
                Case "WON/LOST"
                    LoadControlIntoPanel("~/UserControls/ProjectSummaryWonLost.ascx")
            End Select
 
        Catch ex As Threading.ThreadAbortException
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, strError, App.AppName, App.UserName, False)
            Me.lblError.Text = ex.Message
        End Try
 
    End Sub
    Private Sub LoadControlIntoPanel(controlPath As String)
        'load the correct control in to the placeholder
        PlaceHolder1.Controls.Clear()
        Dim ctrl As Control = LoadControl(controlPath)
        PlaceHolder1.Controls.Add(ctrl)
    End Sub
 
End Class

 

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences