如何从母版页更新内容页?
菜单链接位于母版页中,并且相应的单击事件写入母版页本身。我只有一个内容页。数据以 html 形式保存在数据库中,并且将在相应的菜单链接点击时呈现到内容页面。但问题是内容页面加载发生在母版页之前,因此内容页面是空白的。这里我的代码
public void GetLinkPage(Int32 linkId)//master page
{
LinkContentEnitity linkContent = new LinkContentEnitity();
linkContent = PageController.GetPageContent(linkId);
}
- linkContent
包含 HTML 形式的内容页面。如何在内容页上打印该值?
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 the 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然还不完全清楚,但听起来您是在说您的内容页需要在其自己的 Load 事件中提供信息,该事件是在母版页的
Page_Load
事件中生成的?因此,要么将调用
GetPageLink()
的代码移至内容页面中的PreRender
,要么在 ContentPage 中为Page_LoadComplete()
添加事件处理程序(在加载页面上的所有子控件后触发)并调用 GetPageLink() 并从那里进行渲染,例如在内容页面中:顺便说一句,这是事件顺序的有用参考。在处理嵌套控件(主控/内容、用户控件等)时,您遇到的问题很容易遇到,这有助于很好地理解事件顺序。
http://msdn.microsoft.com/en-us/library/dct97kc3.aspx
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()
toPreRender
in your content page, or add an event handler in ContentPage forPage_LoadComplete()
(which fires after all child controls on a page are loaded) and callGetPageLink()
and do your rendering from there, e.g. in content page: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
一种方法可能是这样...在您的内容页面上,添加一个公共方法来完成您需要完成的工作。在母版页中,将 this.Page 转换为您的页面类并调用该方法。
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.