Let's start with what I'm looking for:
<controls:MyWrapper id="Blah" runat="server">
<content>
<controls:Exporter id="Blah1" runat="server" {This control has an image button and some other controls} />
<controls:GridView {This is a fully functional GridView} />
<controls:CustomFooterDetailer id="Yadda" runat="server" />
</content>
</controls:MyWrapper>
I know I need to create my control, inherits composite control, and create some templates and designers. I have yet to find an example online that explains how to get this particular functionality. I want to restrict the content to only be allowed to use the three controls I showed above, and those controls need to be able to reference the GridView control.
![]() |
0 |
![]() |
here is the basic start ...you will find more help making your custom appear realistic in design mode.
public
class Wrapper : CompositeControl{
private GridView _grid = new GridView();public GridView Grid{
get { return _grid; }set { _grid = value; }}
protected override void CreateChildControls(){
base.CreateChildControls();this.Controls.Add(_grid);// add as many control as you want....
}
}
![]() |
0 |
![]() |
I have no problem with the basics, I'm more concerened with how to get my designer to only allow the three controls I specify, without having to regenerate the GridView HTML logic manually.
![]() |
0 |
![]() |
the control type restriction should be design time or runtime is ok.
![]() |
0 |
![]() |
I figured out how to get my markup the way I want, now I'm having a problem getting the grid to actually display and retain it's settings. I'm obviously doing something wrong, so here's the latest attempt:
Class GridViewControl works properly on it's own, so there's no problems with that class.
Public Class GridViewManager Inherits CompositeControl Implements INamingContainer
Private WithEvents _GridView As GridViewControl
Protected Overrides Sub CreateChildControls() MyBase.CreateChildControls()If _GridView Is Nothing Then _GridView = New GridViewControl Me.Controls.Add(_GridView) End SubProtected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
_GridView =
Me.Controls.Item(0)writer.Write(
"<table cellpadding=""0"" cellspacing=""0"" style=""width:" & _GridView.Width.ToString & ";"">")writer.Write("<tr><td align=""Left"">")_GridView.RenderControl(writer)
writer.Write(
"</td></tr>")writer.Write(
"</table>") End Sub<PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(GetType(GridViewControl))> _ Public Property GridView() As GridViewControl Get Select Case True Case Me.Controls.Count = 0, Me.Controls.Item(0).GetType.Name <> "GridViewControl" Return Nothing Case Else_GridView = Me.Controls.Item(0) Return Me.Controls.Item(0) End Select End GetSet(ByVal value As GridViewControl) Select Case TrueCase Me.Controls.Count = 0 Me.Controls.Add(value) Case Me.Controls.Item(0).GetType.Name <> "GridViewControl"Me.Controls.AddAt(0, value) Case ElseMe.Controls.RemoveAt(0) Me.Controls.AddAt(0, value) End Select
_GridView = value
End Set End PropertyEnd Class
I get a value control on property set, but on render, the control is a blank instantiation.
![]() |
0 |
![]() |
Well, I figured it out. The following is the shell of what it takes to get the desired functional markup I intially posted. I'm still working on this, but I'm guessing that I don't even need the CreateChildControl override with the way I'm managing the child controls. Hope this is helpful to someone, since I wasn't able to find anything online that explained how to do this.Public Class GridViewManager Inherits CompositeControl Implements INamingContainer
Private WithEvents _GridView As GridViewControl
Protected Overrides Sub CreateChildControls() MyBase.CreateChildControls() If GridView IsNot Nothing Then Me.Controls.Add(GridView) End SubProtected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
_GridView =
Me.Controls.Item(0)_GridView.RenderControl(writer)
End Sub<PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(GetType(GridViewControl))> _ Public Property GridView() As GridViewControl Get Select Case True Case Me.Controls.Count = 0, Me.Controls.Item(0).GetType.Name <> "GridViewControl" Return Nothing Case Else _GridView = Me.Controls.Item(0) Return Me.Controls.Item(0) End Select End Get Set(ByVal value As GridViewControl) If value.ID IsNot Nothing Then Select Case True Case Me.Controls.Count = 0 Me.Controls.Add(value) Case Me.Controls.Item(0).GetType.Name <> "GridViewControl" Me.Controls.AddAt(0, value) Case Else Me.Controls.RemoveAt(0) Me.Controls.AddAt(0, value) End Select End If_GridView = value
End Set End PropertyPrivate Sub GridViewManager_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init If Me.Controls.Count > 0 Then If Me.Controls.Item(0).GetType.Name = "GridViewControl" Then _GridView = Me.Controls.Item(0) End If End Sub End Class
![]() |
0 |
![]() |