1

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

因此,在文章页面上,我声明了 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");

这可能吗?

4

2 回答 2

1

您可以在 Page 类内部使用这样的代码:

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

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

this.Comments1.LoadComents(1, "someType");
于 2010-06-04T19:06:38.040 回答
0

在 UserControl Code-Behind 我有以下代码:

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

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

   {
       PageTitle.SetPageTitle(cat.categoryName);
   }

这是工作...

于 2012-05-22T18:22:12.113 回答