PDA

View Full Version : [CLOSED] Create Panel w/MenuPanel at Page_Load in code behind



jwhitmire36
Oct 23, 2014, 5:19 PM
Hello,
I've been through a bunch of posts and tried a lot of different things and I can't for the life of my figure this out. In Page_Load in code behind I am creating a Panel and inside the panel I am creating a MenuPanel, and then the Panel is added to the PlaceHolder. The Panel gets rendered, but for some reason the MenuPanel is not showing up. Please look at my code below and let me know what I'm missing here, I'm using V2.5.1, thanks!




<%@ Page Language="C#"%>
<%@ Register Assembly="Ext.NET" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
Ext.Net.Panel dynPanel = new Ext.Net.Panel()
{
Title = "My Menu",
Height = 400,
Width = 200,
Collapsible = false,
MarginSpec = "20 0 0 20"
};
Ext.Net.MenuPanel menuPanel1 = new MenuPanel();
Ext.Net.Menu menu = new Ext.Net.Menu()
{
ShowSeparator = false,
};
Ext.Net.MenuItem menuItem;
for (int i = 1; i < 5; i++)
{
menuItem = new Ext.Net.MenuItem()
{
ID = "Menu_" + i.ToString(),
Text = "Menu" + i.ToString()
};
menu.Items.Add(menuItem);
}
menuPanel1.Add(menu);
dynPanel.Items.Add(menuPanel1);
this.myPlaceHolder.Controls.Add(dynPanel);
}
</script>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<ext:ResourceManager ID="ExtResourceManager" runat="server" DisableViewState="false" RenderStyles="Embedded" />
<asp:PlaceHolder ID="myPlaceHolder" runat="server"></asp:PlaceHolder>
</body>
</html>


JW

Daniil
Oct 24, 2014, 5:19 AM
Hi @jwhitmire36,

There are two things.

1. The MenuPanel has no height. I would set a FitLayout for the outer Panel.

2. You should put MenuItems directly to a MenuPanel's Menu. No interim Menu is required.

Example

protected void Page_Load(object sender, EventArgs e)
{
Ext.Net.Panel dynPanel = new Ext.Net.Panel()
{
Title = "My Menu",
Height = 400,
Width = 200,
Collapsible = false,
MarginSpec = "20 0 0 20",
Layout = "fit"
};
Ext.Net.MenuPanel menuPanel1 = new MenuPanel();
menuPanel1.Menu.ShowSeparator = false;
Ext.Net.MenuItem menuItem;
for (int i = 1; i < 5; i++)
{
menuItem = new Ext.Net.MenuItem()
{
ID = "Menu_" + i.ToString(),
Text = "Menu" + i.ToString()
};
menuPanel1.Menu.Items.Add(menuItem);
}
dynPanel.Items.Add(menuPanel1);
this.myPlaceHolder.Controls.Add(dynPanel);
}

jwhitmire36
Oct 24, 2014, 3:03 PM
Got it, thanks. I figured it would be something fairly basic I was overlooking. You can close this thread.

Appreciate the help.
JW