Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you access the content of a ASP.NET control?

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

like image 689
Jason Z Avatar asked Oct 28 '08 18:10

Jason Z


1 Answers

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.

like image 126
Dave Ward Avatar answered Nov 03 '22 20:11

Dave Ward