I'm making a website with an Accordion Navigation menu. Some of my menuitems has childNodes so that's no problem but some of my nodes doesn't have childnodes. So it should be possible when I click on that header that I open an other page.
This is my code up till now! But still nothings happen Can somebody help me please?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
AccordionSiteMap_Load(sender, e)
AccordionSiteMap_OpenCurrentPane(sender, e)
End Sub
Protected Sub AccordionSiteMap_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim p As New AjaxControlToolkit.AccordionPane
Dim linkClass, currentLinkClass, nonCurrentLinkClass As String
linkClass = ""
currentLinkClass = "AccordionCurrentLink"
nonCurrentLinkClass = "AccordionLink"If SiteMap.RootNode.HasChildNodes Then
Dim RootNodesEnumerator As IEnumerator = SiteMap.RootNode.ChildNodes.GetEnumerator()
Dim paneCounter As Integer = 0
While RootNodesEnumerator.MoveNext
p = Nothing
p = New AjaxControlToolkit.AccordionPane
p.ID = "Pane" & Regex.Replace(RootNodesEnumerator.Current.ToString(), "\s+", "")
Dim stLink As String = ""If RootNodesEnumerator.Current.url.Equals("") Then
stLink = "<a>" & RootNodesEnumerator.Current.Title & "</a>"Else
stLink = "<a onclick='headerOnClick(" & RootNodesEnumerator.Current.url & ")'>" & RootNodesEnumerator.Current.Title & "</a>"
End If
p.HeaderContainer.Controls.Add(New LiteralControl(stLink))
If RootNodesEnumerator.Current.HasChildNodes Then
Dim ChildNodesEnumerator As IEnumerator = RootNodesEnumerator.Current.ChildNodes.GetEnumerator()
While ChildNodesEnumerator.MoveNext
If SiteMap.CurrentNode Is Nothing Then
linkClass = nonCurrentLinkClass
ElseIf SiteMap.CurrentNode.ToString = ChildNodesEnumerator.Current.ToString Then
linkClass = currentLinkClass
Else
linkClass = nonCurrentLinkClass
End If
p.ContentContainer.Controls.Add(New LiteralControl("<a class='" & linkClass & "' "))
p.ContentContainer.Controls.Add(New LiteralControl("href='" & ChildNodesEnumerator.Current.url & "'>"))
p.ContentContainer.Controls.Add(New LiteralControl(ChildNodesEnumerator.Current.title & "</a><br />"))
End While
End If
myAccordion.Panes.Add(p)
End While
End If
End Sub
Protected Sub AccordionSiteMap_OpenCurrentPane(ByVal sender As Object, ByVal e As EventArgs)
If SiteMap.CurrentNode Is Nothing Then
myAccordion.SelectedIndex = -1
Else
myAccordion.SelectedIndex = RootIndexofCurrentNode(SiteMap.RootNode.ChildNodes)
End If
End Sub
Private Function RootIndexofCurrentNode(ByVal Nodes As SiteMapNodeCollection) As Short
Dim index As Short = -2
If Nodes Is Nothing Then
RootIndexofCurrentNode = -1
ElseIf Nodes.Contains(SiteMap.CurrentNode) Then
RootIndexofCurrentNode = Nodes.IndexOf(SiteMap.CurrentNode)
Else
For Each n As SiteMapNode In Nodes
index = RootIndexofCurrentNode(n.ChildNodes)
If index <> -1 Then
If n.ParentNode.ToString = SiteMap.RootNode.ToString Then
Return SiteMap.RootNode.ChildNodes.IndexOf(n)
Else
Return index
End If
End If
Next
Return -1
End If
End Function
Protected Sub AccordionSiteMap_Load(ByVal sender As Object, ByVal e As EventArgs) Dim p As New AjaxControlToolkit.AccordionPane Dim linkClass, currentLinkClass, nonCurrentLinkClass As String linkClass = "" currentLinkClass = "AccordionCurrentLink" nonCurrentLinkClass = "AccordionLink"
If SiteMap.RootNode.HasChildNodes Then Dim RootNodesEnumerator As IEnumerator = SiteMap.RootNode.ChildNodes.GetEnumerator() Dim paneCounter As Integer = 0 While RootNodesEnumerator.MoveNext p = Nothing p = New AjaxControlToolkit.AccordionPane p.ID = "Pane" & Regex.Replace(RootNodesEnumerator.Current.ToString(), "\s+", "")
If RootNodesEnumerator.Current.url.Equals("") Then p.HeaderContainer.Controls.Add(New LiteralControl("<span>" & RootNodesEnumerator.Current.Title & "</span>")) Else p.HeaderContainer.Controls.Add(New LiteralControl("<span><a href='" & RootNodesEnumerator.Current.url & "'>" & RootNodesEnumerator.Current.Title & "</a></span>")) End If
If RootNodesEnumerator.Current.HasChildNodes Then Dim ChildNodesEnumerator As IEnumerator = RootNodesEnumerator.Current.ChildNodes.GetEnumerator() While ChildNodesEnumerator.MoveNext If SiteMap.CurrentNode Is Nothing Then linkClass = nonCurrentLinkClass ElseIf SiteMap.CurrentNode.ToString = ChildNodesEnumerator.Current.ToString Then linkClass = currentLinkClass Else linkClass = nonCurrentLinkClass End If p.ContentContainer.Controls.Add(New LiteralControl("<a class='" & linkClass & "' ")) p.ContentContainer.Controls.Add(New LiteralControl("href='" & ChildNodesEnumerator.Current.url & "'>")) p.ContentContainer.Controls.Add(New LiteralControl(ChildNodesEnumerator.Current.title & "</a>")) End While End If AccordionSiteMap.Panes.Add(p) End While End If End Sub
Anneleen
Member
24 Points
38 Posts
How to make Accordion Header Click navigate to url and open pane
May 15, 2008 10:54 AM|LINK
Hi,
I'm making a website with an Accordion Navigation menu. Some of my menuitems has childNodes so that's no problem but some of my nodes doesn't have childnodes. So it should be possible when I click on that header that I open an other page.
This is my code up till now! But still nothings happen Can somebody help me please?
This is the asp page
<asp:panel ID="Menu" runat="server" CssClass="pnlMenu"> <ajaxToolkit:Accordion ID="myAccordion" runat="server" SuppressHeaderPostbacks="true" /> </asp:panel>This is the Javascript on this page
This is the code behind the page
Anneleen
Member
24 Points
38 Posts
Re: How to make Accordion Header Click navigate to url and open pane
May 16, 2008 02:07 PM|LINK
I solved it on my own! So I hope that this can help you :)
<asp:panel ID="Menu" runat="server" CssClass="pnlMenu"> <ajaxToolkit:Accordion ID="AccordionSiteMap" runat="server" AutoSize="none" FramesPerSecond="24" RequireOpenedPane="false" SuppressHeaderPostbacks="false" TransitionDuration="500" HeaderCssClass="AccordionHeader" ContentCssClass="AccordionContent" /> </asp:panel>