填充依赖于内容页的母版页控件的最佳方法是什么?

发布于 2024-08-02 01:45:51 字数 221 浏览 6 评论 0原文

我有一个名为 SampleMaster.master 的母版页,该页面包含一个 Repeater 控件

Repeater 控件将用于显示与每个内容页面关联的相关标签,并且标签在内容页面之间会有所不同

数据提取方法 Tags.GetTags() 是工作,但我不知道根据内容页的内容填充母版页中的 Repeater 控件的最佳方法。

代码将驻留在母版页代码后面还是内容页代码后面?

I have a master page called SampleMaster.master and this page contains a Repeater control

The Repeater control will be used to display the relevant tags associated with each content page and the tags will vary between content pages

The data extraction method Tags.GetTags() is working but I do not know the best approach to populate the Repeater control in the master page dependent on what the content page is.

Would the code reside in the masterpage page code behind or the content page code behind?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

楠木可依 2024-08-09 01:45:51

我建议在子页面上公开一个属性或方法,将要显示的标签交给母版页。 例如

partial class myPage : IMyTaggablePage
{
    // the following is an interface member
    public List<string> GetTags()
    {
        return this.Taglist; // assuming taglist was populated somewhere on this page.
    }
}

,然后在您的主页上您可以编写如下内容:

if (this.Page is IMyTaggablePage)
    var tags = (Page as IMyTaggablePage).GetTags();

I would suggest exposing a property or method on the child page which hands the master page the tags to display. For example

partial class myPage : IMyTaggablePage
{
    // the following is an interface member
    public List<string> GetTags()
    {
        return this.Taglist; // assuming taglist was populated somewhere on this page.
    }
}

Then on your master page you can write something like:

if (this.Page is IMyTaggablePage)
    var tags = (Page as IMyTaggablePage).GetTags();
凯凯我们等你回来 2024-08-09 01:45:51

如果可以的话,您应该将其放在主页中。 理想情况下,您的内容页面应该不知道父级,并且应该假设它可以在任何地方使用。

这将为您的内容页面带来更加组件化、可重用的设计。

You should put it in the masterpage if you can. Ideally, your content page should have no knowledge of the parent and should assume that it might be used anywhere.

This will lead to a more componentized, reusable design for your content pages.

指尖上得阳光 2024-08-09 01:45:51

您可以通过内容页公开母版页中的功能,方法是将以下内容添加到内容页 aspx 文件中:

<%@ MasterType VirtualPath="~/MasterPage.master" %>

然后,在您的内容页中,您应该能够访问从母版页公开的任何方法。

因此,您的母版页将具有如下方法:

public void BuildMyCustomStuff(YouInputType in)
{
    // Do something with the data passed in
}

然后在您的内容页面中,您将使用以下方式调用该函数:

Master.BuildMyCustomStuff(dataIn);

You can expose functionality in your master page via your content page by adding the following to you content pages aspx file:

<%@ MasterType VirtualPath="~/MasterPage.master" %>

Then in your content page you should be able to access any methods you exposed from your master page.

So you master page would have a method like:

public void BuildMyCustomStuff(YouInputType in)
{
    // Do something with the data passed in
}

Then in your content page you would call the function with:

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