ASP.NET Get Page control collection at design-time

576 Views Asked by At

Whilst trying to capture the HTML from a Web.UI.Page at design-time (in a UITypeEditor) using the RenderControl method, I noticed that only server controls were being rendered.

So, given this aspx page:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>WebForm1</title>
</head>
<body>
<form id="form1" runat="server">

    Some text

    <asp:Label runat="server" ID="label1">label1</asp:Label> 

    <div>
        <cc1:MyControl ID="MyControl1" runat="server" BorderStyle="Solid" Height="117px" Width="341px" />
    </div>    

    <div style="margin-top:30px;">
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>    

</form>
</body>
</html>

The RenderControl method would render 'label1', 'MyControl1' and 'Button1'. The head and all the divs in the form are all ignored.

I decided to look at the control tree for the page at design-time and this is what I got:

Page
 Label
 MyControl
 Button
 HtmlForm
  LiteralControl

This is what it looks like at run-time:

webform1_aspx
 LiteralControl
 HtmlHead
  HtmlTitle
 LiteralControl
 HtmlForm
  LiteralControl
  Label
  LiteralControl
  MyControl
  LiteralControl
  Button
  LiteralControl
 LiteralControl

Any ideas what is happening here?

0

There are 0 best solutions below