rendering derived control from composite control

Discussion in 'ASP .Net Building Controls' started by William French, Dec 2, 2003.

  1. I am triing to load a control derived from a datagrid into a composite
    control so I can wrap some html around the datagrid. it renders the
    html in the composite control but does not render the dervived
    control. The derived control works fine on it's own. I got most of
    this from an O'reilly book but having trouble figuring the details.
    Any help would be greatly appreciated.

    Dervived Control
    -----------------------------------------
    Imports System.ComponentModel
    Imports System.Web.UI

    <DefaultProperty("Text"), ToolboxData("<{0}:MSSDataGrid
    runat=server></{0}:MSSDataGrid>")> Public Class MSSDataGrid
    Inherits System.Web.UI.WebControls.DataGrid

    End Class

    Composite Control
    ------------------------------------------
    Imports System.ComponentModel
    Imports System.Web.UI

    <ControlBuilder(GetType(MSSDataGridBuilder)), ParseChildren(False)>
    Public Class MSSWrapperControl
    Inherits System.Web.UI.WebControls.DataGrid

    Dim grid As New MSSDataGrid()

    Protected Overrides Sub Render(ByVal output As
    System.Web.UI.HtmlTextWriter)
    output.RenderBeginTag("div")
    RenderChildren(output)
    output.RenderEndTag()
    End Sub

    Protected Overrides Sub RenderChildren(ByVal output As
    HtmlTextWriter)
    If HasControls() Then
    ' Render Children in reverse order.
    Dim i As Integer

    For i = 0 To Controls.Count - 1
    Controls(i).RenderControl(output)
    Next

    End If
    End Sub 'RenderChildren


    Protected Overrides Sub CreateChildControls()
    Controls.Add(grid)
    End Sub

    End Class

    Friend Class MSSDataGridBuilder
    Inherits ControlBuilder

    Public Overrides Function GetChildControlType(ByVal tagName As
    String, ByVal attributes As IDictionary) As Type
    If tagName = "MSSDataGrid" Then
    Dim x As MSSDataGrid
    Return x.GetType
    Else
    Return Nothing
    End If
    End Function

    Public Overrides Sub AppendLiteralString(ByVal s As String)

    End Sub
    End Class

    aspx page
    ------------------------------------------------------------------
    <%@ Register TagPrefix="uc1" Namespace="test" Assembly="test" %>
    <%@ Page Language="vb" AutoEventWireup="false"
    Codebehind="test.aspx.vb" Inherits="test.test"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <title>test</title>
    <meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
    <meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5"
    name="vs_targetSchema">
    <LINK href="Styles.css" type="text/css" rel="stylesheet">
    </HEAD>
    <body topMargin="0" rightMargin="0">
    <form id="Form1" method="post" runat="server">
    <uc1:MSSWrapperControl runat="server" id="msswrappercontrol">
    <uc1:MSSDataGrid runat="server" id="mssdatagrid"
    ShowHeader="False" AutoGenerateColumns="False" GridLines="Horizontal">
    <COLUMNS>
    <ASP:BOUNDCOLUMN HeaderText="CustomerID" DataField="CustomerID"
    />
    <ASP:BOUNDCOLUMN HeaderText="CompanyName"
    DataField="CompanyName" />
    <ASP:BOUNDCOLUMN HeaderText="ContactName"
    DataField="ContactName" />
    </COLUMNS>
    </uc1:MSSDataGrid>
    </uc1:MSSWrapperControl>
    <asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid></form>
    </body>
    </HTML>


    again thank you for any help that can be provided.
    William French, Dec 2, 2003
    #1
    1. Advertising

  2. William French

    Wayne Guest

    See if this will help you figure out your problem, I am doing my a little
    different, the code is VB.NET but it may help.

    Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
    _Password.ApplyStyle(_TextBoxStyle)
    _Password.RenderControl(output)
    End Sub

    Protected Overrides Sub CreateChildControls()
    Controls.Clear()

    _Password = New TextBox
    _Password.TextMode = TextBoxMode.Password
    _Password.ID = "txtPassword"
    Me.Controls.Add(_Password)
    End Sub




    "William French" <> wrote in message
    news:...
    > I am triing to load a control derived from a datagrid into a composite
    > control so I can wrap some html around the datagrid. it renders the
    > html in the composite control but does not render the dervived
    > control. The derived control works fine on it's own. I got most of
    > this from an O'reilly book but having trouble figuring the details.
    > Any help would be greatly appreciated.
    >
    > Dervived Control
    > -----------------------------------------
    > Imports System.ComponentModel
    > Imports System.Web.UI
    >
    > <DefaultProperty("Text"), ToolboxData("<{0}:MSSDataGrid
    > runat=server></{0}:MSSDataGrid>")> Public Class MSSDataGrid
    > Inherits System.Web.UI.WebControls.DataGrid
    >
    > End Class
    >
    > Composite Control
    > ------------------------------------------
    > Imports System.ComponentModel
    > Imports System.Web.UI
    >
    > <ControlBuilder(GetType(MSSDataGridBuilder)), ParseChildren(False)>
    > Public Class MSSWrapperControl
    > Inherits System.Web.UI.WebControls.DataGrid
    >
    > Dim grid As New MSSDataGrid()
    >
    > Protected Overrides Sub Render(ByVal output As
    > System.Web.UI.HtmlTextWriter)
    > output.RenderBeginTag("div")
    > RenderChildren(output)
    > output.RenderEndTag()
    > End Sub
    >
    > Protected Overrides Sub RenderChildren(ByVal output As
    > HtmlTextWriter)
    > If HasControls() Then
    > ' Render Children in reverse order.
    > Dim i As Integer
    >
    > For i = 0 To Controls.Count - 1
    > Controls(i).RenderControl(output)
    > Next
    >
    > End If
    > End Sub 'RenderChildren
    >
    >
    > Protected Overrides Sub CreateChildControls()
    > Controls.Add(grid)
    > End Sub
    >
    > End Class
    >
    > Friend Class MSSDataGridBuilder
    > Inherits ControlBuilder
    >
    > Public Overrides Function GetChildControlType(ByVal tagName As
    > String, ByVal attributes As IDictionary) As Type
    > If tagName = "MSSDataGrid" Then
    > Dim x As MSSDataGrid
    > Return x.GetType
    > Else
    > Return Nothing
    > End If
    > End Function
    >
    > Public Overrides Sub AppendLiteralString(ByVal s As String)
    >
    > End Sub
    > End Class
    >
    > aspx page
    > ------------------------------------------------------------------
    > <%@ Register TagPrefix="uc1" Namespace="test" Assembly="test" %>
    > <%@ Page Language="vb" AutoEventWireup="false"
    > Codebehind="test.aspx.vb" Inherits="test.test"%>
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    > <HTML>
    > <HEAD>
    > <title>test</title>
    > <meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
    > <meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
    > <meta content="JavaScript" name="vs_defaultClientScript">
    > <meta content="http://schemas.microsoft.com/intellisense/ie5"
    > name="vs_targetSchema">
    > <LINK href="Styles.css" type="text/css" rel="stylesheet">
    > </HEAD>
    > <body topMargin="0" rightMargin="0">
    > <form id="Form1" method="post" runat="server">
    > <uc1:MSSWrapperControl runat="server" id="msswrappercontrol">
    > <uc1:MSSDataGrid runat="server" id="mssdatagrid"
    > ShowHeader="False" AutoGenerateColumns="False" GridLines="Horizontal">
    > <COLUMNS>
    > <ASP:BOUNDCOLUMN HeaderText="CustomerID" DataField="CustomerID"
    > />
    > <ASP:BOUNDCOLUMN HeaderText="CompanyName"
    > DataField="CompanyName" />
    > <ASP:BOUNDCOLUMN HeaderText="ContactName"
    > DataField="ContactName" />
    > </COLUMNS>
    > </uc1:MSSDataGrid>
    > </uc1:MSSWrapperControl>
    > <asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid></form>
    > </body>
    > </HTML>
    >
    >
    > again thank you for any help that can be provided.
    Wayne, Dec 3, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sleigh
    Replies:
    1
    Views:
    2,686
    sleigh
    Feb 12, 2004
  2. Replies:
    1
    Views:
    394
    myork
    May 23, 2007
  3. Replies:
    1
    Views:
    386
    Victor Bazarov
    May 23, 2007
  4. Chad
    Replies:
    0
    Views:
    220
  5. Bob Jones

    Composite control - sub control as a property not rendering

    Bob Jones, Apr 6, 2007, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    243
    Bob Jones
    Apr 9, 2007
Loading...

Share This Page