gpt4 book ai didi

c# - 如何从母版页更新内容页?

转载 作者:行者123 更新时间:2023-11-30 21:17:41 25 4
gpt4 key购买 nike

菜单链接在母版页中,相应的点击事件也写在母版页中。我只有一个内容页面。数据以 html 形式保存在数据库中,并在相应的菜单链接点击时呈现到内容页面。但问题是内容页面加载发生在母版页之前,因此内容页面是空白的。这是我的代码-

public void GetLinkPage(Int32 linkId)//master page
{
LinkContentEnitity linkContent = new LinkContentEnitity();
linkContent = PageController.GetPageContent(linkId);
}

linkContent 包含 HTML 格式的内容页面。如何在内容页面上打印此值?

最佳答案

虽然不是很清楚,但听起来您是在说您的内容页面需要在其自己的加载事件中生成的信息,该事件在 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

关于c# - 如何从母版页更新内容页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4669813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com