ASP.NET Easy Menu - Persistance on PostBack

Dynamically added Easy Menu persists on PostBack. We need to use Page_Load and Page_Init events. In the Page_Init method we will create the Easy Menu, set the id and add it to the page's control list. On Page_Load event, if there is no PostBack (!Page.IsPostBack), we will populate the Easy Menu with items and properties. After a postback, Easy Menu is loaded automatically from ViewState.

In page class:
  protected EasyMenu em_1;

Here is the code for Page_Load:
  void Page_Load(object sender, EventArgs e) 
    if (!Page.IsPostBack)
      em_1.AttachTo = "item1";
      em_1.AddItem(new MenuItem("menuItem1", "SubItem 1", "", "", "", 
		"alert('Item 1 - SubItem 1')"));
      em_1.AddItem(new MenuItem("menuItem2", "SubItem 2", "", "", "", 
		"alert('Item 1 - SubItem 2')"));

And the code for Page_Init:
  void Page_Init(object sender, EventArgs e) 
    em_1 = new EasyMenu();
    em_1.ID = "Easymenu1";


Now we need to add a control that posts back the page. For example, a button:

<asp:Button id="Button1" runat="server" Text="PostBack"></asp:Button>

You will notice that even after pressing the button (posting back the page to the server), the Easy Menu will still be populated with its items and properties. Home
Easy Menu Home 
Easy Menu Home
Site Map
Compare with Text Menu
Examples - 79
Appearance - 11
Live Styles
Horizontal Right To Left
Transparent - over flash
With rounded corners
Keep Open New
Expand Animations New
Vertical 1
MS Vertical
Vertical Right To Left
Context Menu - 10
World Map
Style 1
Style 2
Style 3
Right To Left
Tab Strip - 8
Tab Strip
Live Styles
Tab Strip - With postback New
Parent Child Tabstrip New
Tab Strip - Wizard
Tab Strip - Wizard 2
Add / Remove Tabs
Add / Remove Tabs 2
Time Picker - 1
Time Picker
Populating with data - 5
Binding to DataReader New
Binding to DataTable New
Binding to SqlDataSource New
Binding to ObjectDataSource New
Fast loading time
Multi Column Menu - 2
Multi Column Submenu New
Multi Column Submenu with Icons New
Multiple menus - 3
Multiple menus
Multiple menus 2
Horizontal menu and Tab Strip
Operations - 9
ShowEvent New
Add / Remove Items New
Hide / Show Items New
Menu item inner HTML New
Attach / Detach
Menu Events
Menu item postback
Show menu New
Align/Position - 4
Advanced Align
Menu Offsets
Integration  - 14
TreeView - 5
Attach to TreeView
Dynamic Loading
Inside callback panel
Select the TreeView node New
TreeView inside Easy Menu
AJAX Page - 3
Inside AJAX Page panel
Inside MS AJAX panel
Add items server side
Grid - 2
Use With Grid
Inside DataGrid column
Inside WindowNew
Build from SiteMap
Over Java Applet
With Data Controls New
Other features - 12
Menu Icons
Menu Customize
Long vertical menus
Long menu items
Disabled menu item
Dynamic Easy Menu Item
Full Easy Menu width
Hide menu with time delay
Custom sliding effect New
Custom Menu Content New
Knowledge Base - 1
Knowledge Base
Documentation - 4
Server side
Client side
Using the correct path
Tutorials - 2
Using Database
Postback Persistance