views:

220

answers:

2

I was wondering if it is possible to do something like this:

    <uc1:TestControl ID="TestControl1" runat="server">
        <div>More random HTML, etc...</div>
    </uc1:TestControl>

I got an error of "Type 'System.Web.UI.UserControl' does not have a public property named 'div'.". Doing a little research, I found I could add the following property to the server control:

[ParseChildren(false)]
public partial class TestControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

Is it possible to read the content from an ASP.NET control?

Edit: Changed wording to reflect that I am curious if you can do this with either a server or user control

+2  A: 

In a server control, you would create a property that implements ITemplate to contain that content. I'm not positive whether that is possible in a user control, but it may be.

Dave Ward
A: 

yeah it is possible

check this MSDN Article about creating templated user controls, plus you can add [ParseChildren(false)] to the user control class so you can see them from the page holding them. http://msdn.microsoft.com/en-us/library/36574bf6.aspx

hope this helps.