locked
SiteMapPath node event wont update properties ? RRS feed

  • Question

  • User1909155429 posted

    I am trying to alter the parent node to accept a querystring. It seems to change the initial url to a query string url once only. On subsequent events it does not alter the string for the new parameter querystring value? It seems to retain the original url in memory?

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    If IsPostBack = False Then

    AddHandler SiteMap.SiteMapResolve, AddressOf Me.ExpandForumPaths

    end sub

    Public Function ExpandForumPaths(sender As Object, e As SiteMapResolveEventArgs) As SiteMapNode
    Dim currentNode As SiteMapNode = SiteMap.CurrentNode.Clone(True)
    Dim tempNode As SiteMapNode = currentNode

    If tempNode.ParentNode IsNot Nothing Then
    tempNode.ParentNode.Url = tempNode.ParentNode.ToString & "?productid=" & LabelProductID.Text 

    End If

    Return currentNode
    End Function

    Saturday, August 1, 2020 4:21 PM

All replies

  • User-939850651 posted

    hi peterthegreat,

    How to Programmatically Modify Site-Map Nodes in Memory

    SiteMapResolve and dynamic site map paths

    It seems that you want to use querystring to build dynamic nodes. If so, have you read these two articles?

    The SiteMapResolve event is the one to use, but it has some fatal flaws. And the SiteMapResolve is a static method and should never be attached in the page unless it is also unattached in the page.

    Hope this can help you.

    Best regards,

    Xudong Peng

    Monday, August 3, 2020 11:04 AM
  • User1909155429 posted

    I am trying to implement solution and i get error message

    Compiler Error Message: BC30149: Class 'myproject_Seller_CustomerReview3' must implement 'Function SiteMapResolve(sender As Object, e As System.Web.SiteMapResolveEventArgs) As System.Web.SiteMapNode' for interface 'ISiteMapResolver'.

    Source Error:

    Line 7:  Partial Class myproject_Seller_CustomerReview3
    Line 8:      Inherits System.Web.UI.Page
    Line 9:      Implements ISiteMapResolver
    

    my page contains the following code functions:

    Interface ISiteMapResolver
    Function SiteMapResolve(ByVal sender As Object, ByVal e As SiteMapResolveEventArgs) As SiteMapNode
    End Interface

    Public Function SiteMapResolve(ByVal sender As Object, ByVal e As SiteMapResolveEventArgs) As SiteMapNode
    Dim currentNode As SiteMapNode = SiteMap.CurrentNode.Clone(True)
    Dim tempNode As SiteMapNode = currentNode

    If tempNode.ParentNode IsNot Nothing Then
    tempNode.ParentNode.Url = tempNode.ParentNode.Url & "?productid=" & ViewState("ProductID").ToString

    End If

    Return currentNode


    End Function

    Tuesday, August 4, 2020 4:39 PM
  • User-939850651 posted

    Hi peterthegreat,

    I created a simple example, using Session to save querystring, please refer to the following code:

    Class SurroundingClass
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            If IsPostBack = False Then
    
                If Request.QueryString("ProductId") IsNot Nothing Then
                    Response.Write(Request.QueryString("ProductId").ToString())
                End If
    
                SiteMap.SiteMapResolve += AddressOf Me.ExpandForumPaths
            End If
        End Sub
    
        Public Function ExpandForumPaths(ByVal sender As Object, ByVal e As SiteMapResolveEventArgs) As SiteMapNode
            Dim currentNode As SiteMapNode = SiteMap.CurrentNode.Clone(True)
            Dim tempNode As SiteMapNode = currentNode
            If tempNode.ParentNode IsNot Nothing Then tempNode.ParentNode.Url = tempNode.ParentNode.Url.ToString() & "?productid=" + HttpContext.Current.Session("ProductId").ToString()
            Return currentNode
        End Function
    End Class
    <?xml version="1.0" encoding="utf-8" ?>
    <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
      <siteMapNode url="MyWeb.aspx" title="home page"  description="">
        <siteMapNode url="MyWeb1.aspx" title="First test page"  description="" />
        <siteMapNode url="MyWeb2.aspx" title="Second test page"  description="" />
      </siteMapNode>
    </siteMap>
    

    Result:

    If I misunderstand what you mean, could you provide relevant sample code?

    Best regards,

    Xudong Peng

    Tuesday, August 18, 2020 8:59 AM
  • User1909155429 posted

    My problem was i did not know how to resolve this issue with 

     Implements ISiteMapResolver
    My page did not recognise the statement which is required to run the code?
    every time i opened the page and ran the function the querystring value remained the same, it did not update.
    i found the solution but could not implement it because of the reason mention.

    Thanks
    Monday, August 24, 2020 9:21 PM