rendering derived control from composite control

W

William French

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.
 
W

Wayne

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top