stubborn SiteMapNode refuses to update

Last post 01-05-2006 4:28 PM by RichardMathis. 5 replies.

Sort Posts:

  • stubborn SiteMapNode refuses to update

    12-23-2005, 7:28 PM
    • Participant
      755 point Participant
    • RichardMathis
    • Member since 11-17-2002, 9:38 PM
    • Las Vegas, NV
    • Posts 165

    Hello,

       I am experimenting with the navigation tools, and at this point I'm trying to get the breadcrumb control to update based on the querystring.

    I made this function.

    Private Function ShowCurrentnode(ByVal sender As Object, ByVal e As SiteMapResolveEventArgs) As SiteMapNode

    Dim currentnode As SiteMapNode = SiteMap.CurrentNode.Clone(True)

    Dim tempnode As SiteMapNode = currentnode

    tempnode.Title = objcategory.Title

    Return currentnode

    End Function

    call this in the pageload event

    If Not Page.IsPostBack Then

    If Not Request.QueryString("id") Is Nothing Then

    objcategory = adaptercontentcats.GetDataByID(Request.QueryString("id"))(0)

    End If

    End If

    AddHandler SiteMap.SiteMapResolve, AddressOf Me.ShowCurrentnode

     

    and it works once...  After that, the breadcrumb "sticks" to whatever the first load was, never calling the sitemapresolve event again. 

    Can anyone look at my code and tell me what I'm doing wrong?

     

    Thank you in advance,

    Richard Mathis
    Dndorks Webmaster
    http://dndorks.com/
    TopWebcomics Webmaster
    http://topwebcomics.com/
  • Re: stubborn SiteMapNode refuses to update

    12-27-2005, 2:26 PM
    • Contributor
      4,347 point Contributor
    • dannychen
    • Member since 08-24-2004, 12:17 PM
    • Redmond, WA
    • Posts 840
    • AspNetTeam
      Moderator

    The SiteMapProvider is global to your entire application, not an instance based on the request.  That means that any SiteMapResolve handlers are applied to every request as soon as they are set up.  The best place for code like this is in Global.asax.  Take a look at the sample in the "Personal WebSite Starter Kit". 
    --
    Danny

    disclaimer: Information provided is 'as is' and conveys no warranties or guarantees.
  • Re: stubborn SiteMapNode refuses to update

    01-03-2006, 12:08 PM
    • Participant
      755 point Participant
    • RichardMathis
    • Member since 11-17-2002, 9:38 PM
    • Las Vegas, NV
    • Posts 165

    That worked great for me Danny!  I guess I should probably stop looking in what apparantly are outdated MSDN articles and focus more on tearing apart the sample applications. :)

    Now I do worry about this sort of scenario because if I want to convert a portion of the querystring  into a new breadcrumb title, then it means another database call (one in the global sitemapresolve event and another in the page).  Is there a better way to pass this sort of information back and forth? 

    Richard Mathis
    Dndorks Webmaster
    http://dndorks.com/
    TopWebcomics Webmaster
    http://topwebcomics.com/
  • Re: stubborn SiteMapNode refuses to update

    01-03-2006, 1:25 PM
    • Contributor
      4,347 point Contributor
    • dannychen
    • Member since 08-24-2004, 12:17 PM
    • Redmond, WA
    • Posts 840
    • AspNetTeam
      Moderator

    Richard,
      It sounds like you have a url that is:  mypage.aspx?a=b&c=d and, a title "my page", and you would like, for example, to have the title say:  "my page: b"  where b comes from the query string.  Currently you are using a DB access to requery the value for b?  In thise case, I think you could use templating kind of like this...

    <%@ Page Language="VB" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <
    script runat="server">
        Private Function Filter(ByVal title As String, ByVal url As String) As String
            Return "T:" & title & "U:" & url
        
    End Function
    </
    script>

    <
    html xmlns="http://www.w3.org/1999/xhtml" >
    <
    head runat="server">
        <title>Untitled Page</title>
    </
    head>
    <
    body>
        <form id="form1" runat="server">
        <div>
            <asp:SiteMapPath ID="SiteMapPath1" runat="server" >
            <CurrentNodeTemplate>
                <asp:Label runat="server" ID="Label1" Text='<%# Filter( Eval("title"), Eval("url")) %>' />
            </CurrentNodeTemplate>
            </asp:SiteMapPath>
        
        
    </div>
        </form>
    </
    body>
    </
    html>


    If I'm totally wrong, let me know and I'll try and come up with an answer that is more for what you're doing.
    --
    Danny
    disclaimer: Information provided is 'as is' and conveys no warranties or guarantees.
  • Re: stubborn SiteMapNode refuses to update

    01-03-2006, 2:59 PM
    • Participant
      755 point Participant
    • RichardMathis
    • Member since 11-17-2002, 9:38 PM
    • Las Vegas, NV
    • Posts 165

    Thats exactly what I'm doing, I didn't know I could template the sitemappath like that, thats awesome.  Too many new things in asp.net 2.0 not enough spare learning time to thoroughly go through each one. :)

    Richard Mathis
    Dndorks Webmaster
    http://dndorks.com/
    TopWebcomics Webmaster
    http://topwebcomics.com/
  • Re: stubborn SiteMapNode refuses to update

    01-05-2006, 4:28 PM
    • Participant
      755 point Participant
    • RichardMathis
    • Member since 11-17-2002, 9:38 PM
    • Las Vegas, NV
    • Posts 165

    Ok, Hopefully last thing and not sure if its possible in an efficient manner.

    I'm using URL Rewriting to convert /content/4.aspx into

    /content.aspx?id=4

    Using the sitenode template I can pull my content object from my database just once and assign the proper title for that ID along with all the formatting and content with just 1 database pull.  This creates something like: Home > Caesars Palace Hotel and Casino

    Is it possible to create a dynamic site hierarchy with just 1 database pull?  In other words, I'd like it to look like: Home > Las VegasCaesars Palace Hotel and Casino

     Now I can see how to add nodes in the global.asax (which would require a second database pull), or I could just alter my function to output a link going to the content category plus the ">" plus the content title, but basically I'm asking if there is a best practices way of doing this I should be aware of.
    Richard Mathis
    Dndorks Webmaster
    http://dndorks.com/
    TopWebcomics Webmaster
    http://topwebcomics.com/
Page 1 of 1 (6 items)