我已经阅读了大量同样问题的帖子,我研究了很多解决方案,但我仍然无法解决我的问题。
我有一个母版页和一个嵌套用户控件的default.aspx。
default.aspx :
<%@ Register TagPrefix="uc" TagName="MenuSideUserControl" Src="~/Controls/MenuSide.ascx" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<div class="row">
</div>
<div class="row">
<div id="sideMenu">
<uc:MenuSideUserControl runat="server" ID="wkfMenuSide">
</uc:MenuSideUserControl>
</div>
<div id="remoteContent">
</div>
</div>
</asp:Content>
default.aspx.vb:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
AddHandler wkfMenuSide.UserControlLinkClick, AddressOf MenuSide_UserControlLinkClick
End Sub
Protected Sub MenuSide_UserControlLinkClick(sender As Object, e As EventArgs)
Dim parentId = CType(sender, LinkButton).CommandArgument
_menuSide.BuildSideMenu(_dao.GetMenuItems(_userID, parentId))
End Sub
MenuSide.ascx:
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="MenuSide.ascx.vb" Inherits="IntranetWKF.MenuSide" %>
<div class="col-sm-2" style="padding-left: 0;">
<div runat="server" class="panel-group" id="accordion" ClientIDMode="Static">
</div>
</div>
MenuSide.ascx.vb
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
BuildSideMenu(_dao.GetMenuItems(0, 3))
End Sub
Public Sub BuildSideMenu(sideMenuItems As IList(Of WkfMenuItem))
Dim pnlDefault As HtmlGenericControl
Dim pnlHeading As HtmlGenericControl
Dim pnlTitle As HtmlGenericControl
Dim linklist As HtmlGenericControl
Dim link As LinkButton
Dim lastRegroupement = String.Empty
For Each m As WkfMenuItem In sideMenuItems
pnlDefault = New HtmlGenericControl
With pnlDefault
.TagName = "div"
.Attributes("class") = "panel panel-default"
End With
[...]
link = New LinkButton
With link
.Text = m.libelle
End With
If Not String.IsNullOrEmpty(m.url) Then : link.PostBackUrl = m.url
Else
With link
.CommandArgument = m.id
.CommandName = "parentId"
.ClientIDMode = ClientIDMode.Static
.Attributes("data-parentid") = m.id
End With
AddHandler link.Click, AddressOf LinkButtonClicked
End If
pnlTitle.Controls.Add(link)
pnlHeading.Controls.Add(pnlTitle)
pnlDefault.Controls.Add(pnlHeading)
accordion.Controls.Add(pnlDefault)
End If
Next
End Sub
Public Event UserControlLinkClick As EventHandler
Protected Sub LinkButtonClicked(sender As Object, e As EventArgs)
RaiseEvent UserControlLinkClick(Me, e)
End Sub
我使用事件和委托,并将委托绑定到LinkButton
。
在default.aspx Page_Load中(我也在OnInit事件中尝试过)我绑定了一个永远不会被触发的点击处理方法,这是我没有解决方案的地方。
那些LinkButton
必须重建他们在点击时嵌套的菜单。
最终目标是更新菜单和内容ajax。