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

    <P mce_keep="true">Hi gerrymac, </P>
    <P mce_keep="true">[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]</P>
    <P mce_keep="true"> </P>
    <P mce_keep="true">Please, use "Page_Init" instead of "Page_Load" to remove/add new items to C1Menu.<BR></P>
    <P mce_keep="true"> </P>
    <P mce_keep="true">For example following code will work fine:</P>Default.aspx:<BR><%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="C1Menu_Default" %>
    <P><%@ Register Assembly="C1.Web.UI.Controls.2" Namespace="C1.Web.UI.Controls.C1Menu" TagPrefix="cc1" %></P><!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">
    <P><head runat="server"></P><title>Untitled Page</title> </head>
    <P><body></P>
    <P><form id="form1" runat="server"></P>
    <P><div></P>
    <P><asp:ScriptManager ID="ScriptManager1" runat="server"></P>
    <P></asp:ScriptManager></P><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    <P><cc1:C1Menu id="C1menu0" runat="server"></P>
    <P></cc1:C1Menu></P>
    <P></div></P></form> </body>
    <P></html></P>
    <P mce_keep="true">Default.aspx.vb :<BR> -----------------------------------------------------------</P>
    <P>Imports C1.Web.UI.Controls.C1Menu</P>Partial Class C1Menu_DefaultInherits System.Web.UI.Page
    <P mce_keep="true"> </P>Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
    <P>C1menu0.Items.Clear()</P>C1menu0.Items.Add(New C1MenuItem("Item 1"))
    <P>C1menu0.Items.Add(New C1MenuItem("Item 2")) </P>
    <P>C1menu0.Items.Add(New C1MenuItem("Item 3")) </P>End Sub
    <P>Protected Sub C1menu0_ItemClick(ByVal sender As Object, ByVal e As C1.Web.UI.Controls.C1Menu.C1MenuEventArgs) Handles C1menu0.ItemClick</P>Dim menuItemRef As C1MenuItem
    <P>menuItemRef = e.Item</P>
    <P>Label1.Text = menuItemRef.Text + " Clicked"</P>
    <P>End Sub</P>Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub
    <P>End Class</P>
    <P> </P>
    <P> </P>
    <P>--- Best regards, Dmitri.</P>
  • 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

    <P mce_keep="true">Hi Gerry,<BR><BR>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.</P>
    <P mce_keep="true">-- Best regards, Dmitri.</P>
Need extra support?

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

Learn More

Forum Channels