Avatar of Elliott Ward
Elliott Ward

asked on 

Can a SiteMapNode have a blank URL property?

I have witten a SiteMapProvider that connects to SQL and feeds a ASP 2.0 Treeview control.  I would like to have "Menu Placeholders" on the menu that do not have any url's assigned to them.  Howmight I accomplish this?

If I just set the URL property to "" the node no longer appears on my map.

Thank you so much for any help.
ASP.NETVisual Basic.NET

Avatar of undefined
Last Comment
Elliott Ward
Avatar of REA_ANDREW
REA_ANDREW
Flag of United Kingdom of Great Britain and Northern Ireland image

Just as a test, assign # as the value of the URL.  Have you written the code from scrtach for your provider?  if so it may be useful to post some code to help.

Andrew
Avatar of Elliott Ward
Elliott Ward

ASKER

I have attached the code that I am using to create the node.  When I use "#" for the URL I recieve an error message that duplicate URLs are not allowed.  

Thank you
If reader.IsDBNull(url) Then
   node = New SiteMapNode(Me, reader.GetInt32(id).ToString(), "", reader.GetString(title), IIf(reader.IsDBNull(desc), Nothing, reader.GetString(desc)))
Else
   node = New SiteMapNode(Me, reader.GetInt32(id).ToString(), reader.GetString(url), reader.GetString(title), IIf(reader.IsDBNull(desc), Nothing, reader.GetString(desc)))
End If

Open in new window

Avatar of REA_ANDREW
REA_ANDREW
Flag of United Kingdom of Great Britain and Northern Ireland image

ok when you create a SiteMapNode without a URL are you assigning to it any children?

As I think it is because of the absence of child nodes why it does not display.

Andrew
Avatar of Elliott Ward
Elliott Ward

ASKER

Here is the full code for the provider.
Imports System.Collections.Generic
Imports System.Data.SqlClient
Imports System.Web.Configuration
Public Class SqlSiteMapProvider
    Inherits StaticSiteMapProvider
    Shared ReadOnly _errmsg1 As String = "Missing connectionStringName attribute"
    Shared ReadOnly _errmsg2 As String = "Duplicate node ID"
    Private _root As SiteMapNode = Nothing
    Private _connect As String
 
    Public Overloads Overrides Sub Initialize(ByVal name As String, ByVal attributes As NameValueCollection)
        MyBase.Initialize(name, attributes)
 
        If attributes Is Nothing Then
            Throw New System.Configuration.ConfigurationErrorsException(_errmsg1)
        End If
 
        _connect = attributes("connectionStringName")
        If [String].IsNullOrEmpty(_connect) Then
            Throw New System.Configuration.ConfigurationErrorsException(_errmsg1)
        End If
    End Sub
 
    <System.Runtime.CompilerServices.MethodImpl(Runtime.CompilerServices.MethodImplOptions.Synchronized)> _
    Public Overloads Overrides Function BuildSiteMap() As SiteMapNode
        ' Return immediately if this method has been called before 
        If _root IsNot Nothing Then
            Return _root
        End If
 
        ' Create a dictionary for temporary node storage and lookup 
        Dim nodes As New Dictionary(Of Integer, SiteMapNode)(16)
 
        ' Query the database for site map nodes 
        Dim connection As New SqlConnection(WebConfigurationManager.ConnectionStrings(_connect).ConnectionString)
        Try
            connection.Open()
            Dim command As New SqlCommand("SELECT ID, Title, Description, Url, " + "Roles, Parent FROM SiteMap ORDER BY ID", connection)
            Dim reader As SqlDataReader = command.ExecuteReader()
            Dim id As Integer = reader.GetOrdinal("ID")
            Dim url As Integer = reader.GetOrdinal("Url")
            Dim title As Integer = reader.GetOrdinal("Title")
            Dim desc As Integer = reader.GetOrdinal("Description")
            Dim roles As Integer = reader.GetOrdinal("Roles")
            Dim parent As Integer = reader.GetOrdinal("Parent")
 
            If reader.Read() Then
                ' Create the root SiteMapNode 
                _root = New SiteMapNode(Me, reader.GetInt32(id).ToString(), IIf(reader.IsDBNull(url), Nothing, reader.GetString(url)), reader.GetString(title), IIf(reader.IsDBNull(desc), Nothing, reader.GetString(desc)))
 
                If Not reader.IsDBNull(roles) Then
                    Dim rolenames As String = reader.GetString(roles).Trim()
                    If Not [String].IsNullOrEmpty(rolenames) Then
                        Dim rolelist As String() = rolenames.Split(New Char() {","c, ";"c}, 512)
                        _root.Roles = rolelist
                    End If
                End If
 
                ' Add "*" to the roles list if no roles are specified 
                If _root.Roles Is Nothing Then
                    _root.Roles = New String() {"*"}
                End If
 
                ' Record the root node in the dictionary 
                If nodes.ContainsKey(reader.GetInt32(id)) Then
                    Throw New System.Configuration.ConfigurationErrorsException(_errmsg2)
                End If
                nodes.Add(reader.GetInt32(id), _root)
 
                ' Add the node to the site map 
                AddNode(_root, Nothing)
 
                ' Build a tree of SiteMapNodes underneath the root 
                While reader.Read()
                    'Dim node As New SiteMapNode(Me, reader.GetInt32(id).ToString(), IIf(reader.IsDBNull(url), Nothing, reader.GetString(url)), reader.GetString(title), IIf(reader.IsDBNull(desc), Nothing, reader.GetString(desc)))
                    Dim node As SiteMapNode = Nothing
 
                    If reader.IsDBNull(url) Then
                        node = New SiteMapNode(Me, reader.GetInt32(id).ToString(), Nothing, reader.GetString(title), IIf(reader.IsDBNull(desc), Nothing, reader.GetString(desc)))
                    Else
                        node = New SiteMapNode(Me, reader.GetInt32(id).ToString(), reader.GetString(url), reader.GetString(title), IIf(reader.IsDBNull(desc), Nothing, reader.GetString(desc)))
                    End If
 
                    If Not reader.IsDBNull(roles) Then
                        Dim rolenames As String = reader.GetString(roles).Trim()
                        If Not [String].IsNullOrEmpty(rolenames) Then
                            Dim rolelist As String() = rolenames.Split(New Char() {","c, ";"c}, 512)
                            node.Roles = rolelist
                        End If
                    End If
 
                    ' If the node lacks roles information, 
                    ' "inherit" that information from its parent 
                    Dim parentnode As SiteMapNode = nodes(reader.GetInt32(parent))
                    If node.Roles Is Nothing Then
                        node.Roles = parentnode.Roles
                    End If
 
                    ' Record the node in the dictionary 
                    If nodes.ContainsKey(reader.GetInt32(id)) Then
                        Throw New System.Configuration.ConfigurationErrorsException(_errmsg2)
                    End If
                    nodes.Add(reader.GetInt32(id), node)
 
                    ' Add the node to the site map 
                    AddNode(node, parentnode)
                End While
            End If
        Finally
            connection.Close()
        End Try
 
        ' Return the root SiteMapNode 
        Return _root
    End Function
 
    Protected Overloads Overrides Function GetRootNodeCore() As SiteMapNode
        BuildSiteMap()
        Return _root
    End Function
End Class

Open in new window

Avatar of REA_ANDREW
REA_ANDREW
Flag of United Kingdom of Great Britain and Northern Ireland image

"As I think it is because of the absence of child nodes why it does not display.
"

Can you confirm my aboce comment please and either evaluate it is true or false.  Add a child node.
Avatar of Elliott Ward
Elliott Ward

ASKER

I did add a child node and there was no change.  The node was not visable.
ASKER CERTIFIED SOLUTION
Avatar of Elliott Ward
Elliott Ward

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo