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

MenuItem of 2nd and 3rd Menus ..Server Click Event not firing

5 Answers 123 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Neal
Top achievements
Rank 1
Neal asked on 27 May 2008, 09:56 AM
Hi,  some help needed please

I have 3 menus (expanded/outlook type) in a Nav Pane and Loading into a content Pane.

I have the first menu's server side click working using  (C#..override onInit  etc working fine)
the other two however,..applying the same logic however do not recognise and fire their respective set up click events.
What am I missing?



I am using Telerik Q4 2006 ASPNet 2.

The code is  beneath (I have excluded the 3rd menu for brevity,..but should be same logic problem as second menu)

The FindControl for each menu is also fine,..just the click event for menus 2 and 3 not firing

Thanks
Neal

override

protected void OnInit(EventArgs e)
{
 InitializeComponent();
 base.OnInit(e);
}

private void InitializeComponent()

{

//find the first radmenu...it is in an ItemTemplate

RadMenu TopRadMenu =

(

RadMenu)this.RadPanelbar1.Controls[0].Controls[0].FindControl("RadMenu1");

if (TopRadMenu != null)

{

TopRadMenu.ItemClick +=

new RadMenuEventHandler(this.Menu1_ItemClick);

this.Load += new EventHandler(this.Page_Load);

}

//find the second radmenu...it is in an ItemTemplate

//?this.RadPanelbar1.Controls[1].Controls[0].Controls[1]

RadMenu MidRadMenu =

(

RadMenu)this.RadPanelbar1.Controls[1].Controls[0].FindControl("Radmenu2");

if (MidRadMenu != null)

{

MidRadMenu.ItemClick +=

new RadMenuEventHandler(this.Menu2_ItemClick);

this.Load += new EventHandler(this.Page_Load);

}

//find the third radmenu...it is in an ItemTemplate

//?this.RadPanelbar_RP.Controls[0].Controls[0].Controls[1]

RadMenu BtmRadMenu =

(

RadMenu)this.RadPanelbar_RP.Controls[0].Controls[0].FindControl("Radmenu3");

if (BtmRadMenu != null)

{

BtmRadMenu.ItemClick +=

new RadMenuEventHandler(this.Menu3_ItemClick);

this.Load += new EventHandler(this.Page_Load);

}

}


protected void Page_Load(object sender, EventArgs e)

{

//Recreacte the user control for each page-lifecycle since we are adding it dynamically to the page

LoadUserControl(

this.selectedUC);

}

public void LoadUserControl(string userControl)

{

//Load user control onto page

Control selectedUserControl = Page.LoadControl(userControl);

//Generate an Unique ID based the control path

string uniqueID = this.selectedUC.Split('.')[0];

uniqueID = uniqueID.Replace(

"/", "").Replace("~", "");

selectedUserControl.ID = uniqueID;

//Load control into Required Panel

//...and prevent controls from being loaded twice..weird error,..??

if (TopContentPanel.FindControl(selectedUserControl.ID) == null)

{

TopContentPanel.Controls.Add(selectedUserControl);

}

}

public void ReloadUserControl()

{

//Loads the UCtl from the Property,...usually set from the UCtl..hence Public property

TopContentPanel.Controls.Clear();

LoadUserControl(

this.selectedUC);

}

private void Menu1_ItemClick(object sender, RadMenuEventArgs e)

{

RadMenuItem ItemClicked = e.Item;

string Temp = FullPath(ItemClicked);

//Given we have the name of the menu item clicked,...

//Load the Required UserControl

switch (FullPath(ItemClicked))

{

case "Occurrence Book":

this.selectedUC = "OpsOccurrenceLogs.ascx";

break;

case "Operations":

this.selectedUC = "Operations.ascx";

break;

//Ops Locations ..Locations per each Operation current and old

case "Ops Locations":

this.selectedUC = "Locations.ascx";

break;

default:

this.selectedUC = "OpsOccurrenceLogs.ascx";

break;

}

ReloadUserControl();

}

private void Menu2_ItemClick(object sender, RadMenuEventArgs e)

{

//Co-ordinators resources

RadMenuItem ItemClicked = e.Item;

string Temp = FullPath(ItemClicked);

switch (FullPath(ItemClicked))

{

case "Documents":

this.selectedUC = "Documents.ascx";

break;

case "Contacts":

this.selectedUC = "Contacts.ascx";

break;

case "RolePlayers":

this.selectedUC = "RPlayers.ascx";

break;

 

default:

this.selectedUC = "RPlayers.ascx";

break;

}

ReloadUserControl();

}

// I do use RadAjaxManager1_ResolveUpdatedControls

//

@

Page Language="C#" AutoEventWireup="true" CodeFile="DRM OperationsMngr.aspx.cs"

Inherits="Drm_OPSMainForm" %>

<%

@ Register Assembly="RadAjax.Net2" Namespace="Telerik.WebControls" TagPrefix="radA" %>

<%

@ Register Assembly="RadMenu.Net2" Namespace="Telerik.WebControls" TagPrefix="radM" %>

<%

@ Register TagPrefix="radp" Namespace="Telerik.WebControls" Assembly="RadPanelbar.NET2" %>

 

<!

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 id="Head1" runat="server">

<title>Ops manager</title>

<link rel="stylesheet" type="text/css" href="Style.css"/>

</

head>

<

body>

<form id="form1" runat="server">

<div id="FormDiv" style="width:100%; height:100%; border:solid ,1,gray">

<radA:RadAjaxManager ID="RadAjaxManager1" runat="server" >

<AjaxSettings>

<radA:AjaxSetting AjaxControlID="RadMenu1">

<UpdatedControls>

<radA:AjaxUpdatedControl ControlID="TopContentPanel" />

</UpdatedControls>

</radA:AjaxSetting>

<radA:AjaxSetting AjaxControlID="Radmenu2">

<UpdatedControls>

<radA:AjaxUpdatedControl ControlID="BottomContentPanel" />

</UpdatedControls>

</radA:AjaxSetting>

</AjaxSettings>

</radA:RadAjaxManager>

<asp:Panel

ID="TopNavPanel"

runat="server"

CssClass="TopNavPanel"

ScrollBars="Auto">

<radp:RadPanelbar ID="RadPanelbar1" runat="server" Width="190px"

Skin="Outlook" height="100%" >

<Items>

<radp:RadPanelItem Text="DM Admin" runat="server"

Expanded="true" Width="100%" BorderStyle="none">

<Items>

<radp:RadPanelItem runat="server" >

<ItemTemplate>

<radm:RadMenu ID="RadMenu1"

runat="server"

Flow="Vertical" Width="100%" Height="100%"

>

<Items>

<radm:RadMenuItem ID="OccurrenceBook"

runat="server"

BackColor="#404040" ForeColor="Silver"

Text="Occurrence Book"

Width="100%" >

<GroupSettings ExpandDirection="Down"

Width="90px" />

</radm:RadMenuItem>

<radm:RadMenuItem ID="Operations" runat="server"

BackColor="#404040" ForeColor="Silver"

Text="Operations"

Width="100%" >

<GroupSettings ExpandDirection="Down"

Width="90px" />

</radm:RadMenuItem>

<radm:RadMenuItem ID="Locations" runat="server"

BackColor="#404040" ForeColor="Silver"

Text="Locations"

Width="100%" >

<GroupSettings ExpandDirection="Down"

Width="90px" />

</radm:RadMenuItem>

</Items>

</radm:RadMenu>

</ItemTemplate>

</radp:RadPanelItem>

</Items>

</radp:RadPanelItem>

<radp:RadPanelItem Text="DM Resources" Expanded="True"

runat="server" >

<Items>

<radp:RadPanelItem runat="server">

<ItemTemplate>

<radm:RadMenu ID="Radmenu2" runat="server"

Flow="Vertical" Width="100%">

<Items>

<radm:RadMenuItem ID="RPlayers" runat="server"

BackColor="#404040" ForeColor="Lime"

Text="RolePlayers"

Width="100%"

Target="TopContentPanel">

<GroupSettings ExpandDirection="Down" Width="90px" />

</radm:RadMenuItem>

<radm:RadMenuItem ID="Contacts" runat="server"

BackColor="#404040" ForeColor="Lime"

Text="Contacts"

Width="100%"

Target="TopContentPanel">

<GroupSettings ExpandDirection="Down" Width="90px" />

</radm:RadMenuItem>

<radm:RadMenuItem ID="Documents" runat="server"

BackColor="#404040" ForeColor="Lime"

Text="Documents"

Width="100%"

Target="TopContentPanel">

<GroupSettings ExpandDirection="Down" Width="90px" />

</radm:RadMenuItem>

</Items>

</radm:RadMenu>

</ItemTemplate>

</radp:RadPanelItem>

</Items>

</radp:RadPanelItem>

</Items>

</radp:RadPanelbar>

</asp:Panel>

<asp:Panel ID="TopContentPanel" runat="server" CssClass="TopContentPanel">

</asp:Panel>

<asp:Panel ID="BottomNavPanel" runat="server"

CssClass="BottomNavPanel" ScrollBars="Auto">

</asp:Panel>

<asp:Panel ID="BottomContentPanel" runat="server" CssClass="BottomContentPanel">

</asp:Panel>

<asp:Panel ID="FooterCommsPanel" runat="server" CssClass="FooterCommsPanel">

</asp:Panel>

</div>

</form>

</body>


5 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 27 May 2008, 11:44 AM
Hello Neal,

Could you verify (with the aid of the debugger) that your code successfully attached the event handlers? I suspect the menu instances remain "null" and the event subscription code never executes.
You should use the following syntax to access child controls of templated items:

RadMenu menu = (RadMenu)RadPanelbar1.Items[0].Items[0].FindControl("RadMenu1");

Accessing the Controls collection of the panelbar or items may lead to unexpected results because the panel items are controls themselves.

I hope this helps,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Neal
Top achievements
Rank 1
answered on 27 May 2008, 01:38 PM
Thanx,  the first one was always correct
i.e.
RadMenu menu = (RadMenu)RadPanelbar1.Items[0].Items[0].FindControl("RadMenu1");


the second needed   "Controls[1]."

RadMenu

MidRadMenu =(RadMenu)this.RadPanelbar1.Controls[1].Controls[0].FindControl("Radmenu2");

but , it causes IE to open a new window now (no postback/runat server ....with
 "javascript:__doPostBack('RadPanelbar1$p1$p0$Radmenu2','RadPanelbar1$p1$p0$Radmenu2$m0')  in the AddressBar and
with the Message  "Internet Explorer cannot display the webpage" 

0
Atanas Korchev
Telerik team
answered on 27 May 2008, 02:52 PM
Hello Neal,

I have prepared a sample web site which works fine on my end (using the latest official Q1 2008 release). Please find it attached.

Regards,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Neal
Top achievements
Rank 1
answered on 28 May 2008, 01:37 PM
Hi and Thanks,
but no cigar unfortunately.

I did change my C# to Items[].FindControl  (after removing the extra unneccessary RadpanelItem.  and each of the 3 menus were found (and referenced) correctly.

I removed my RadAjaxManager from the aspx,..no Luck either.
The CodeBehind for the Click Events on the 2nd and 3rd menu are not firing,..
The __DoPostback java script appears immediately after clicking, in the address bar.

May be the parameters passed to the postback before it gets to the Server code are the problem?
eg Selecting the 2nd Menu in the RadPanelBar1

"javascript:__doPostBack('RadPanelbar1$p1$p0$Radmenu2','RadPanelbar1$p1$p0$Radmenu2$m0')  in the AddressBar with the Message  "Internet Explorer cannot display the webpage" in the body

or the 3rd menu in the RadPanelbar_RP  (which is $p0 $p0..
i.e. Item[0].item[0].Radmenu3

javascript:__doPostBack('RadPanelbar_RP$p0$p0$Radmenu3','RadPanelbar_RP$p0$p0$Radmenu3$m0')

Only Menu1 fires and loads correctly...weird
At this point in terms of aspx , the only difference is I have my RadPanelBar inside an asp:Panel, 
Maybe its a version thing,..  I use Q4 2006?

Can you try it in version Q4 1.6??

TIA
Neal

<asp:Panel

ID="TopNavPanel"

runat="server"

CssClass="TopNavPanel">

<radp:RadPanelbar ID="RadPanelbar1" runat="server" Width="190px" Skin="Outlook" height="100%" >

<Items>

<radp:RadPanelItem Text="DM Admin" Expanded="True" runat="server">

<Items>

<radp:RadPanelItem>

<ItemTemplate>

<radm:RadMenu ID="RadMenu1" Skin="Outlook"

runat="server"

Flow="Vertical" Width="100%" Height="100%"

>

<Items>

<radm:RadMenuItem ID="OccurrenceBook"

runat="server"

Text="Occurrence Book"

Width="100%" >

<GroupSettings ExpandDirection="Down"

Width="90px" />

</radm:RadMenuItem>

<radm:RadMenuItem ID="Operations" runat="server"

Text="Operations"

Width="100%" >

<GroupSettings ExpandDirection="Down"

Width="90px" />

</radm:RadMenuItem>

<radm:RadMenuItem ID="Locations" runat="server"

BackColor="#404040" ForeColor="Silver"

Text="Locations"

Width="100%" >

<GroupSettings ExpandDirection="Down"

Width="90px" />

</radm:RadMenuItem>

</Items>

</radm:RadMenu>

</ItemTemplate>

</radp:RadPanelItem>

</Items>

</radp:RadPanelItem>

<radp:RadPanelItem Text="DM Resources" Expanded="True" runat="server" >

<Items>

<radp:RadPanelItem>

<ItemTemplate>

<radm:RadMenu ID="Radmenu2" runat="server"

Flow="Vertical" Width="100%">

<Items>

<radm:RadMenuItem ID="RPlayers" runat="server"

BackColor="#404040" ForeColor="Lime"

Text="RolePlayers"

Width="100%"

Target="TopContentPanel">

<GroupSettings ExpandDirection="Down" Width="90px" />

</radm:RadMenuItem>

<radm:RadMenuItem ID="Contacts" runat="server"

BackColor="#404040" ForeColor="Lime"

Text="Contacts"

Width="100%"

Target="TopContentPanel">

<GroupSettings ExpandDirection="Down" Width="90px" />

</radm:RadMenuItem>

<radm:RadMenuItem ID="Documents" runat="server"

BackColor="#404040" ForeColor="Lime"

Text="Documents"

Width="100%"

Target="TopContentPanel">

<GroupSettings ExpandDirection="Down" Width="90px" />

</radm:RadMenuItem>

</Items>

</radm:RadMenu>

</ItemTemplate>

</radp:RadPanelItem>

</Items>

</radp:RadPanelItem>

</Items>

</radp:RadPanelbar>

</asp:Panel>

private void InitializeComponent()

{

RadMenu TopRadMenu = (RadMenu)RadPanelbar1.Items[0].Items[0].FindControl("RadMenu1");

if (TopRadMenu != null)

{

TopRadMenu.ItemClick +=

new RadMenuEventHandler(Menu1_ItemClick);

}

RadMenu MidRadMenu = (RadMenu)RadPanelbar1.Items[1].Items[0].FindControl("Radmenu2");

if (MidRadMenu != null)

{

MidRadMenu.ItemClick +=

new RadMenuEventHandler(Menu2_ItemClick);

}

RadMenu BtmRadMenu = (RadMenu)this.RadPanelbar_RP.Items[0].Items[0].FindControl("Radmenu3");

if (BtmRadMenu != null)

{

BtmRadMenu.ItemClick +=

new RadMenuEventHandler(Menu3_ItemClick);

}

}



0
Accepted
Atanas Korchev
Telerik team
answered on 28 May 2008, 01:45 PM
Hello Neal,

Removing the Target property of the second menu items seems to fix the issue.

I hope this helps,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Menu
Asked by
Neal
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Neal
Top achievements
Rank 1
Share this question
or