How do you access the contents of an ASP.NET control?

I was wondering if one could do something like this:

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

I have a "Type" error. System.Web.UI.UserControl 'does not have a public property named "div". "With a little research, I found that I can add the following property to manage the server:

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

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

Edit: The wording has been changed to reflect that I am wondering if you can do this using server or user management

+6
controls
source share
2 answers

In the server control, you will create a property that implements ITemplate to contain this content. I'm not sure if this is possible in a user control, but it could be.

+4
source share

Yes maybe

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

hope this helps.

0
source share

All Articles