Custom Composite Control - How to: <CompositeControl><GridView ...><Columns /></GridView></CompositeControl> with little effort

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
StephenSkinner
7/24/2007 3:55:41 PM
asp.net.custom-server-controls 3498 articles. 0 followers. Follow

5 Replies
1477 Views

Similar Articles

[PageSpeed] 22
Get it on Google Play
Get it on Apple App Store

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
mzd
7/24/2007 6:54:29 PM

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
StephenSkinner
7/24/2007 7:08:39 PM

the control type restriction should be design time or runtime is ok.

0
mzd
7/24/2007 7:20:00 PM

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 Sub

 

Protected 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 Get

Set(ByVal value As GridViewControl)

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

_GridView = value

End Set

End Property

 

End Class

 

 

I get a value control on property set, but on render, the control is a blank instantiation.

0
StephenSkinner
7/24/2007 9:48:55 PM

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 Sub

Protected 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 Property

 

Private 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
StephenSkinner
7/25/2007 3:56:20 PM
Reply:

Similar Artilces:

>>>> Heads up <<<<
I just got a warning from Norton that "PamelaSetup-Basic.exe" has a virus in it. The name is "VirusBurst" Luckily, I did not install this software and Norton's quarantined it so I could delte it, which I have done. Symantec has not completed analysis of this particular piece of garbage but it did catch the sig. If you have installed Pamela, you may be in trouble. Duffy wrote: > I just got a warning from Norton that "PamelaSetup-Basic.exe" has a virus > in it. The name is "VirusBurst" > > Luckily, I did not install...

>>>> ROOT Exploit in SAMBA <<<<<<
"A flaw has been detected in the Samba main smbd code which could allow an external attacker to remotely and anonymously gain Super User (root) privileges on a server running a Samba server. This flaw exists in previous versions of Samba from 2.0.x to 2.2.7a inclusive. This is a serious problem and all sites should either upgrade to Samba 2.2.8 immediately or prohibit access to TCP ports 139 and 445." http://us3.samba.org/samba/samba.html Binaries are available from Samba for RedHat, and some other distributions. So far as I can tell, the RedHat update mirrors I norm...

C<< >> vs C<< >> vs C<< x >>
Ugh. So we all know that there's this syntax for formatting codes (n=E9s "interio= r sequences") like C<< x >>. And that tokenizes as three tokens: "C<< ", open-C code "x", content " >>" close-code matching the C open-code And this is explicated by what I wrote in perlpodspec where I say that such a code... * starts with a capital letter (just US-ASCII [A-Z]) followed by two or more "<"'s, one or more whitespace characters, * any number of characters * one or more whit...

>>>> BUY RAM <<<<
.. ~~~*@@@*~~~ ================================================== ================================================== ENTER HERE: >>> http://web-for-you.cn/about/buy-ram <<< ================================================== ================================================== .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ...

>>>> CAPITALS GAMES <<<<
.. ~~~!!!~~~ ================================================== ================================================== CLICK HERE TO ENTER: >>> http://web-paradise.cn/3/capitals-games <<< ================================================== ================================================== .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ....

>>>> BLU-RAY MOVIES <<<<
.. ~~~!!!~~~ ================================================== ================================================== CLICK HERE TO ENTER: >>> http://web-paradise.cn/2/blu-ray-movies <<< ================================================== ================================================== .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ....

[PATCH] correctly handle C<< >> and C<<< >>> in diagnostics
This is just a quick hack; ideally someone would make it use an actual pod parser. --- perl/lib/diagnostics.pm.orig 2003-12-30 15:48:47.000000000 -0800 +++ perl/lib/diagnostics.pm 2004-05-25 01:54:31.735904000 -0700 @@ -314,10 +314,10 @@ sub noop { return $_[0] } # spensive for a noop sub bold { my $str =$_[0]; $str =~ s/(.)/$1\b$1/g; return $str; } sub italic { my $str = $_[0]; $str =~ s/(.)/_\b$1/g; return $str; } - s/[BC]<(.*?)>/bold($1)/ges; + s/C<<< (.*?) >>>|C<< (.*?) >>|[BC]<(.*?)>/bold($+)/ges; ...

How to strip a string of <html>, ,</html>, <body>, </body>, <form ... >, </form> tags?
I have stream which is the HTML input of a page. Now I want to use only that part of this page, that is within <form .....> and </form> tags, and excluding these tags.How would I go about stripping <html>, ,</html>, <body>, </body>, <form ... >, </form>, <head> and </head> tags? I have to make sure that <head ...javascript..> and its corresponding </head> tags are not stripped in this process.sun21170    Wait... you said you wanted to strip the head tags, and you're also saying you need to NOT strip the ...

The Man Who Debunks Virus Myths <<<hero???>>>R.Rosenberger Vmyths.com!!!<<<SIGH>>>
http://www.securitynewsportal.com/article.php?sid=1368&mode=thread&order=0 -- Regard: Joh@nnes´┐Ż 1216771 Ont.Inc. "Nothing is more damaging to a new truth than an old error" Take a look at the following from the article: (Begin quote) "Rosenberger is not just a random ornery writer with a website and a bone to pick. He's an experienced programmer, a systems administrator and a man of mystery with high-level CIA security clearance. Information about Rosenberger's status with the CIA was confirmed by an inquiry to a government office, and Ro...

Difference between <% %> <%# %> <%= %> ?
I have some server controls to which I want to assign the visible property using the server tags instead of code behind, but I can't manage to do it, so far I'm using:     Public Shared Function accesible(ByVal user As USERRow) As Boolean        Select Case user.rol            Case "Administrator"                Return True            Cas...

>>>BOOKMARKS<<<
I dont understand the hep page for Lsot Bookmarks - can someone guide me please? I need to know what to look for (instructions in how to do it) As I dont know what im doing im new to using PC's RAJA SINGH wrote: > I dont understand the hep page for Lsot Bookmarks - can someone guide me > please? I need to know what to look for (instructions in how to do it) As I > dont know what im doing im new to using PC's please keep your posting together so we can follow whats going on. Thanks. Close FF. Now, using your file manager, locate the FF profile. To l...

<<<THUD>>>
http://www.novell.com/support/search.do?cmd=displayKC&docType=kc&externalId=3882364&sliceId=1&docTypeID=DT_TID_1_1&dialogID=104807193&stateId=0%200%20104803654 Novell actually gave a projected release date for something? <ponders if this date is before or after the new maintenance policy kicks in> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 First, terrible subject line. Second, the offender has been shot. ;-) Not really.... this guy is awesome just because he is crazy like that. Third, before the patch date stuff (February I think). Goo...

How about <<< and >>> ops?
This has probably come up before, but I think it would be good if perl had two additional arithemetic operators: >>> would be a right shift _without_ sign extension under use integer (currently, under use integer, >> is at the mercy of the underlying C lib). <<< would be a left roll ($x <<< $y would be equivalent to ( ($x << $y) | (2**$y-1) & ($x >> (32-$y)) ) these two ops would come in handy when implementing cryptographic algorithms. I guess you could argue that >>> should be a right roll, but then I don'...

[PATCH] Fix POD: C<...->...> => C<< ...-> ... >>
--=-0nPiZliXhb80VRfJ/8qX Content-Type: text/plain Content-Transfer-Encoding: 7bit See the attached patch, it fixes some POD which gets rendered wrong by newer POD rendering tools. Thanks, Frank --=-0nPiZliXhb80VRfJ/8qX Content-Disposition: attachment; filename="0001-Fix-POD-C-.-.-C.patch" Content-Type: text/x-patch; name="0001-Fix-POD-C-.-.-C.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit From ed46d8dd56e57d51347cb0a7a6397687ee15a950 Mon Sep 17 00:00:00 2001 From: Frank Wiegand <frank.wiegand@gmail.com> Date: Thu, 19 Nov 2009 1...

Web resources about - Custom Composite Control - How to: <CompositeControl><GridView ...><Columns /></GridView></CompositeControl> with little effort - asp.net.custom-server-controls

Resources last updated: 12/12/2015 10:06:04 AM