开发者

Where should I populate a control based on a selected value from master page

I have the following situation:

  • Master page contains a tree control
  • Page use the previous master page
  • Control populates its items based on the selected node in the tree (which is in the master page)

The question is: Where should I populate a control based on a selected value from master page?

The problem is that the Load event of the master page is fired after the Load event of the page, so I couldn't handle the sel开发者_如何学运维ected node from the master page in the Load event of the page.

I tried also to use the PreRender event of the page, but the control is not populated true.

Any help!


Based on your question I'm guessing you are building/binding the list in the masterpage's load event and then reading the selected index/value in the child pages load event.

Instead try building/binding in the masterpage init event, then reading it in the pages load event should be no problem.


Set the NavigateUrl to the page which should be loaded and pass the selected node value as query strings.

In the example below, I'd subscribed to OnTreeNodeDataBound event on the TreeView. In the event handler, I'd customized the NavigateUrl by adding query string (in this case selected node value).

ex:

TreeView Markup in Master page:

<asp:TreeView ID='TreeView1' runat='server' DataSourceID='SiteMapDataSource1' OnTreeNodeDataBound='HandleOnTreeViewTreeNodeDataBound'>        
</asp:TreeView>

code-behind:

public void HandleOnTreeViewTreeNodeDataBound(Object sender, TreeNodeEventArgs e)
{
        String newUrl = String.Format("{0}?nodeValue={1}", e.Node.NavigateUrl, e.Node.Value);
        e.Node.NavigateUrl = newUrl;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜