I am adding menu items programmatically so I can control which ones appear based on the role of the user. My problem is that every menu item I add behaves as if it has been clicked on during the load. Stripped to bare bones, here is the simplified code:
Public Class test2 Inherits System.Web.UI.Page Private Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init If Not IsPostBack Then CreateMenu() End If End Sub Private Sub CreateMenu() MainMenu.Items.Add(New MenuItem("Home", "", "/Peak.aspx")) End Sub End Class
The test2.aspx contains:
<form id="form1" runat="server"> <asp:Menu ID="MainMenu" runat="server" > <Items> </Items> </asp:Menu> </form>
This is all the code in Peak.aspx.vb:
Public Class Peak Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load MsgBox("This should not appear but does!!") End Sub End Class
The Peak.aspx Page_Load is being loaded and the message box displayed, when test2 is set as the start up page. My real code has several menu items added and CreateMenu causes ALL the page_Loads to be being triggered with a large overhead!
Is this a bug or something I can switch off, and is there a workaround?