从父页面调用 Web 用户控件的函数

发布于 2024-09-04 03:14:09 字数 480 浏览 0 评论 0原文

我正在创建一个评论网络用户控件。我想在不同的页面上使用此评论控件,例如:文章、景点和类别。

因此,在文章页面上,我声明了 Web 用户控件。

 <uc1:Comments ID="Comments1" runat="server"  />

在该控件上,有一个函数调用 loadComments

public void LoadComents(int ID,string type)
{
        //Load the comments into an asp.net repeater that resides on the control 
}

,一旦验证文章存在,我就想调用该函数。 所以在文章页面上我想做一些类似

Comments1.LoadComents(101,"article");

这可能吗?

I'm creating a comments web user control. I want to use this comments control on distinct pages like: articles, attractions and categories.

So, on the articles page I declare the Web User Control

 <uc1:Comments ID="Comments1" runat="server"  />

On the control, there is a function call loadComments

public void LoadComents(int ID,string type)
{
        //Load the comments into an asp.net repeater that resides on the control 
}

which I want to call once I have validated that the article exists.
So on the article page I want do something like

Comments1.LoadComents(101,"article");

Is this possible?

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

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

发布评论

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

评论(2

感情废物 2024-09-11 03:14:09

您可以在 Page 类内部使用如下代码:

Comments commentsControl = this.FindControl("Comments1");
commentsControl.LoadComents(1, "someType");

或者,如果该控件存在于 Designer 中的页面上,您应该能够执行如下简单操作:

this.Comments1.LoadComents(1, "someType");

You can use code like this from inside of your Page class:

Comments commentsControl = this.FindControl("Comments1");
commentsControl.LoadComents(1, "someType");

Or if the control exists on the page in Designer, you should be able to do something as simple as:

this.Comments1.LoadComents(1, "someType");
似狗非友 2024-09-11 03:14:09

在 UserControl 代码隐藏上,我有以下代码:

    public void SetPageTitle(string strTitle)
    {
        lPageTitle.Text = strTitle;
    }

在包含/包含 UserControl 的页面代码隐藏上,

   {
       PageTitle.SetPageTitle(cat.categoryName);
   }

这正在工作......

On the UserControl Code-Behind I have the following code:

    public void SetPageTitle(string strTitle)
    {
        lPageTitle.Text = strTitle;
    }

On the Page Code-Behind that contains/included the UserControl

   {
       PageTitle.SetPageTitle(cat.categoryName);
   }

This is working ...

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