.NET Ektron 8.6 : How to use value in query string for Ektron Server Control MenuModel (TreeFilter.Id)

StackOverflow https://stackoverflow.com/questions/17196881

  •  01-06-2022
  •  | 
  •  

Question

I am trying to pass a value that the ektron:MenuModelSource.TreeFilter control will use to generate the given menu. I am able to get the value from the query string

I am working on the menu solution and am stumped on what to do differently.

I am needing to set the Id for the TreeFilter property of the web server control below:

<ektron:MenuModelSource ID="menuModelSource2" runat="server">
  <TreeFilter Id="355" Depth="1" />
</ektron:MenuModelSource>

I am passing a query string that looks like: ?top=355&side=375&low=123 .This way an id can be passed for each menu to be used by each designated TreeFilter on a page. I am also able to pull in that info to the code behind file and convert it to an int for use by the TreeFilter (all of the following code is done in PageLoad):

string sideIdstr = Request.QueryString["side"];
int sideId = Convert.ToInt32(sideIdstr);
menuModelSource2.TreeFilter.Id = sideId;

However, the MenuModelSource.TreeFilter is still rendering the 355 menu rather than the 375 menu.

I can “verify” that the id has indeed been changed to 375 by using the following:

Response.Write("<h1>" + menuModelSource2.TreeFilter.Id + "</h1>");

… which shows 375 on the page.

What should I be doing instead to get the TreeFilter to use the id from the query string? Someone suggested trying DataBind() on the server controls, but I still get the same results. Here is my current code:

protected void Page_Load(object sender, EventArgs e)
{
    Ektron.Cms.API.Content.Content ContentAPI = new Ektron.Cms.API.Content.Content();
    Page.Title = ContentAPI.GetContent(PageHost1.PageID).Title;
    string sideIdstr = Request.QueryString["side"];
    int sideId = Convert.ToInt32(sideIdstr);
    menuModelSource2.TreeFilter.Id = sideId;
    menuModelSource2.DataBind();
    menuView2.DataBind();
    Response.Write("<h1>" + menuModelSource2.TreeFilter.Id + "</h1>");
}

…and my markup is this…

<ektron:MenuModelSource ID="menuModelSource2" runat="server">
  <TreeFilter Id="355" Depth="1" />
</ektron:MenuModelSource>
<ektron:MenuView ID="menuView2" runat="server" ModelSourceID="menuModelSource2">
  <ListTemplate>
    <ul id="menunav" runat="server" class="unstyled subnav">
      <asp:PlaceHolder ID="listPlaceholder" runat="server" />
    </ul>
  </ListTemplate>
  <ItemTemplate>
    <li <%# ((Eval("Type").ToString().ToLower() == "submenu")) ? @" class=""subnav""" : @" class=""menuitem""" %>>
      <asp:HyperLink ID="nodeLink" runat="server" Text='<%# Eval("Text") %>' NavigateUrl='<%# Utility.getNavigateUrl( Eval("NavigateUrl") ) %>' />
      <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
    </li>
  </ItemTemplate>
</ektron:MenuView> 

If anyone has a better way of doing this such as using the Ektron Framework API I would be open to that as well.

Was it helpful?

Solution

After updating the parameters of the Model source you need to call LoadData on the model source. However that method is not public, so you need to do this trick using reflection to call the method.

 menuModelSource2.GetType().GetMethod("LoadData", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy).Invoke(menuModelSource2, new object[] { });

This is documented at reference.ektron.com See the aspx.cs tab. It's at the bottom.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top