开发者

Call a function of a Web User Control from the parent page

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

开发者_如何学Cpublic 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?


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");


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 ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜