我正试图创建一个简单的菜单用户控件,正如此处。
附加的代码导致了一个“对象引用未设置为对象实例”的错误,但我不知道为什么。有什么想法吗?
<%@ Master Language="VB" CodeFile="MySite.master.vb" Inherits="MySite" %>
<%@ Register src="Controls/Menu.ascx" tagname="Menu" tagprefix="my" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>MySite</title>
<link href="Styles/MySite.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder id="headContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body id="masterBody" runat="server">
<form id="form1" runat="server">
<my:Menu ID="Menu1" runat="server">
<MenuItems>
<my:MenuItem Text="Test" NavigateUrl="~/Default.aspx" />
</MenuItems>
</my:Menu>
</form>
</body>
</html>
Partial Class Controls_Menu
Inherits System.Web.UI.UserControl
Private m_Items As List(Of MenuItem) = Nothing
<PersistenceMode(PersistenceMode.InnerProperty)> _
Public Property MenuItems() As List(Of MenuItem)
Get
Return m_Items
End Get
Set(ByVal value As List(Of MenuItem))
m_Items = value
End Set
End Property
End Class
Public Class MenuItem
Private m_Text As String
Public Property Text() As String
Get
Return m_Text
End Get
Set(ByVal value As String)
End Set
End Property
Private m_NavigateUrl As String
Public Property NavigateUrl() As String
Get
Return m_NavigateUrl
End Get
Set(ByVal value As String)
m_NavigateUrl = value
End Set
End Property
End Class