ANP
ANP

Reputation: 15607

How to access an usercontrol from the code behind?

I have an usercontrol with fck editor for allowing user to add note in my aspx page, which allows the user all kind of text formatting.My need is that I have to access user control from the code behind and collect the content as the same format some one has entered in the fck editor.How can I do this?

Upvotes: 2

Views: 2607

Answers (2)

djdd87
djdd87

Reputation: 68466

I'll elaborate on Brian's answer. You need to expose the content from the UserControl by adding a public property:

public string Content
{
   get
   {
      return editor.Content;
   }
}

Then to get the content from the user control, just called the property from the Page's code beind:

protected void Page_Load(object sender, EventArgs e)
{
   string content = this.UserControl1.Content;
}

Upvotes: 3

Brian Mains
Brian Mains

Reputation: 50728

In the page, the page code-behind should be able to use it directly like:

this.uc1.<uc code-behind properties or methods>

So you can expose things from your user control by adding public properties or methods.

Upvotes: 0

Related Questions