如何从母版页更新内容页?

发布于 2024-10-11 15:01:53 字数 400 浏览 0 评论 0原文

菜单链接位于母版页中,并且相应的单击事件写入母版页本身。我只有一个内容页。数据以 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奈何桥上唱咆哮 2024-10-18 15:01:53

虽然还不完全清楚,但听起来您是在说您的内容页需要在其自己的 Load 事件中提供信息,该事件是在母版页的 Page_Load 事件中生成的?

因此,要么将调用 GetPageLink() 的代码移至内容页面中的 PreRender,要么在 ContentPage 中为 Page_LoadComplete() 添加事件处理程序(在加载页面上的所有子控件后触发)并调用 GetPageLink() 并从那里进行渲染,例如在内容页面中:

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
}

顺便说一句,这是事件顺序的有用参考。在处理嵌套控件(主控/内容、用户控件等)时,您遇到的问题很容易遇到,这有助于很好地理解事件顺序。

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() 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

月牙弯弯 2024-10-18 15:01:53

一种方法可能是这样...在您的内容页面上,添加一个公共方法来完成您需要完成的工作。在母版页中,将 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文