我正在创建评论Web用户控制。我想对以下不同页面进行此评论控制:文章,景点和类别。

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

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

在控件上,有一个函数调用加载量

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

一旦我验证了文章的存在,我想打电话给我。因此,在文章页面上,我想做类似的事情

Comments1.LoadComents(101,"article");

这可能吗?

有帮助吗?

解决方案

您可以从页面内部使用这样的代码:

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

或者,如果该控件在设计师的页面上存在,则应该能够做一些简单的事情:

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

其他提示

在USERCONTROL CODE-BEHIND上,我有以下代码:

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

在包含/包含usercontrol的页面代码上

   {
       PageTitle.SetPageTitle(cat.categoryName);
   }

这正在工作...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top