C1 Menu Item.Click method not firing

Posted by: gerrymac on 10 September 2017, 11:26 am EST

  • Posted 10 September 2017, 11:26 am EST

    I have emailed the following problem to c1 support. but I have received no response. So I will try here:


    When items are added to C1menu manuallly, the ItemClick event does not fire.
    I have added a menuitems at design-time and they work ok.

    See the following very simple example:

    Partial Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    LoadControls()
    End Sub

    Private Sub Loadcontrols()

    With C1Menu1
    .Items.Add(New C1.Web.UI.Controls.C1Menu.C1MenuItem("My Menu Item"))
    End With
    End Sub

    Private Sub C1Menu1_ItemClick(ByVal sender As Object, ByVal e As C1.Web.UI.Controls.C1Menu.C1MenuEventArgs) Handles C1Menu1.ItemClick
    Me.Label1.Text = "Menu Pressed"
    End Sub

    End Class
  • Replied 10 September 2017, 11:26 am EST

    Hi gerrymac, 


    [quote user="gerrymac"]I have emailed the following problem to c1 support. but I have received no response. So I will try here: When items are added to C1menu manuallly, the ItemClick event does not fire. I have added a menuitems at design-time and they work ok. See the following very simple example: Partial Public Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load LoadControls() End Sub Private Sub Loadcontrols() With C1Menu1 .Items.Add(New C1.Web.UI.Controls.C1Menu.C1MenuItem("My Menu Item")) End With End Sub Private Sub C1Menu1_ItemClick(ByVal sender As Object, ByVal e As C1.Web.UI.Controls.C1Menu.C1MenuEventArgs) Handles C1Menu1.ItemClick Me.Label1.Text = "Menu Pressed" End Sub End Class[/quote]


     


    Please, use "Page_Init" instead of "Page_Load" to remove/add new items to C1Menu.


     


    For example following code will work fine:

    Default.aspx:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="C1Menu_Default" %>

    <%@ Register Assembly="C1.Web.UI.Controls.2" Namespace="C1.Web.UI.Controls.C1Menu" TagPrefix="cc1" %>


    Untitled Page










    Default.aspx.vb :
     -----------------------------------------------------------


    Imports C1.Web.UI.Controls.C1Menu

    Partial Class C1Menu_DefaultInherits System.Web.UI.Page

     

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

    C1menu0.Items.Clear()

    C1menu0.Items.Add(New C1MenuItem("Item 1"))

    C1menu0.Items.Add(New C1MenuItem("Item 2"))


    C1menu0.Items.Add(New C1MenuItem("Item 3"))

    End Sub

    Protected Sub C1menu0_ItemClick(ByVal sender As Object, ByVal e As C1.Web.UI.Controls.C1Menu.C1MenuEventArgs) Handles C1menu0.ItemClick

    Dim menuItemRef As C1MenuItem

    menuItemRef = e.Item


    Label1.Text = menuItemRef.Text + " Clicked"


    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub

    End Class


     


     


    --- Best regards, Dmitri.

  • Replied 10 September 2017, 11:26 am EST

    Hi Dmitri,

    That worked, thank you.

    But why can the Page_Load method not be used as the menu may need to be changed dynamically
    as the page is submitted?

    Regards

    Gerry
  • Replied 10 September 2017, 11:26 am EST

    Hi Gerry,

    This is because control handles postback data before Page_Load event but in your original sample menu structure changed when postback data already loaded by menu.


    -- Best regards, Dmitri.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels