how to update content page from master page?
Menu links are in the master page and and the corresponding click events are written in the master page itself. I have only one content page. Data is saved in html form in t开发者_如何学Che DB and that will be rendered to the content page on corresponding menu link clicks. But the problem is content page load occurs before the master page so the content page is blank. Here my code-
public void GetLinkPage(Int32 linkId)//master page
{
LinkContentEnitity linkContent = new LinkContentEnitity();
linkContent = PageController.GetPageContent(linkId);
}
linkContent
contains that content page in HTML form. How can I print this value on content page?
Though it's not entirely clear, it sounds like you are saying your content page needs information in its own Load event that is generated in the Page_Load
event of the master page?
So either move the code that calls GetPageLink()
to PreRender
in your content page, or add an event handler in ContentPage for Page_LoadComplete()
(which fires after all child controls on a page are loaded) and call GetPageLink()
and do your rendering from there, e.g. in content page:
protected override void OnInit(EventArgs e)
{
Page.LoadComplete += new EventHandler(Page_LoadComplete);
}
protected void Page_LoadComplete(object sender, EventArgs e) {
// do stuff here, instead of OnLoad/Page_Load event
}
By the way this is a useful reference for event order. The problem you are having is very easy to get into when dealing with nested controls (master/content, usercontrols, etc), it helps to have a good understanding of the event order.
http://msdn.microsoft.com/en-us/library/dct97kc3.aspx
One way to do it might be this... On your content page, add a public method that does the work you need done. In the master page, cast this.Page to your page class and call that method.
精彩评论