Custom Server Control to render multiple Controls

I have a need to build a reusable "Custom Server Control" that will in turn render multiple controls at runtime.

The four controls I need it to render are as follows 

	<asp:Label ID="divLogin" runat="server" Text=" | " />
	<asp:LoginStatus CssClass="footer" ID="LoginStatus1" runat="server" LogoutPageUrl="Default.aspx" />
	<asp:Label ID="divAdmin" runat="server" Text=" | " />
	<asp:HyperLink CssClass="footer" ID="btnAdmin" NavigateUrl="#" runat="server">Dashboard</asp:HyperLink></div>

Has anyone got any insight into this?


Thanks in advance!


Visual Studio 2008
ASP.NET 3.5 (Visual Basic)
SQL Server Express

Check out my blog
2/26/2009 3:15:59 AM 3498 articles. 0 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 29

I figured this one out on my own.


Namespace ICMS.Controls
    Public Class DashboardLinks : Inherits WebControl : Implements INamingContainer

        Protected Overrides Sub CreateChildControls()
            Dim qs As String = HttpContext.Current.Request.QueryString("ID")
            If Not CInt(qs) = Settings.PageID Then Settings.Dispose_Instance()
            Dim s As Settings = If(qs Is Nothing, Settings.Instance(Nothing), Settings.Instance(CInt(qs)))

            Dim divider1, divider2, divider3 As New Label
            divider1.Text = " | "
            divider2.Text = " | "
            divider3.Text = " | "

            'Add the initial divider
            If _ShowFirstDivider = True Then Me.Controls.Add(divider1)

            Dim lb As New LoginStatus
            With lb
                .ID = "LoginStatus1"
                .LogoutPageUrl = "Default.aspx"
                .CssClass = _CssClass
                AddHandler .LoggingOut, AddressOf LoginStatus1_LoggingOut
            End With

            If HttpContext.Current.User.Identity.IsAuthenticated Then
                'Add the second divider

                Dim Dash As New HyperLink
                With Dash
                    .CssClass = _CssClass
                    .NavigateUrl = "#"
                    .Attributes.Add("onclick", "openWin(" & s.ID & ",'Admin'); return false;")
                    .Text = "Dashboard"
                End With

            End If

            If _ShowLastDivider = True Then Me.Controls.Add(divider3)

        End Sub
        Friend _CssClass As String
        Friend _ShowFirstDivider As Boolean = True
        Friend _ShowLastDivider As Boolean = False

        Public Shadows Property CssClass() As String
                Return _CssClass
            End Get
            Set(ByVal value As String)
                _CssClass = value
            End Set
        End Property
        Public Property ShowFirstDivider() As Boolean
                Return _ShowFirstDivider
            End Get
            Set(ByVal value As Boolean)
                _ShowFirstDivider = value
            End Set
        End Property
        Public Property ShowLastDivider() As Boolean
                Return _ShowLastDivider
            End Get
            Set(ByVal value As Boolean)
                _ShowLastDivider = value
            End Set
        End Property

        Private Sub LoginStatus1_LoggingOut(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs)

                Dim httpContext As System.Web.HttpContext = httpContext.Current
                Dim vURL As String = httpContext.Items("UrlRewritingNet.UrlRewriter.VirtualUrl").ToString()
                Dim vQS As String = httpContext.Items("UrlRewritingNet.UrlRewriter.ClientQueryString").ToString()
                Dim newURL As String = vURL.Replace("?" + vQS, "")
            Catch : End Try

        End Sub
    End Class
End Namespace

Visual Studio 2008
ASP.NET 3.5 (Visual Basic)
SQL Server Express

Check out my blog
3/1/2009 5:34:38 AM

Similar Artilces:

how to have both server controls and html controls rendered in a custom control?
I have a custom control in which there is an html text box.when you click on it , a div containing a table is appeared and according to what you select in that table a text is set to the text box. It works fine but the problem is: as the text box is an html element it doesn't have viewstate and when a post back occures in the page its value disappeares.I tried a hidden field to keep its value.again there is another problem : I put this custom control in a usercontrol and put the usercontrol in a multiview and by clicking on a button this view is selected and by clicking another bu...

Usercontrol vs Custom Server Controls, Any need for Custom Server Controls
Hello I'm new to ASP.Net so this is probably a stupid question but, is there any need to create customer server controls now that you can pre-compile usercontrols into a dll and thus easily share between applications? This blog post from David Ebb describes how to do it and the restrictions he note don't seem that bad (other than being able to embed resources such as images in the dll). His article desribes the techniques for ASP.Net 2.0 and he suggests that there will be further improvements in .Net 3.5 in this ar...

problems listenening to events on a custom server control from another custom server control
 Hi all,I am having problems listening to events on one of custom server controls(AddBookmark) from another custom server control(BookmarkList). The listener or the BookmarkList control has a property that can be set to the AddBookmark control (string at design but the reference is obtained at run-time). I am able to get a reference to the AddBookmark control and add a listener to it on the BookmarkList control on the OnPrender of BookmarkList. But the problem is that when the events on AddBookmark gets fired, the listener added from the BookmarkList is no longer present and the listene...

Custom Server Control Vs Web Parts, Any need for Custom Server Control
Hello I've just posted a similar question on why you need server controls when you can pre-compile usercontrols and redistribute them. I've seen lots of (usercontrol vs web part) but not much on web part vs custom server control. According to the MSDN site you can put web parts onto a normal page outside of a web part zone and they behave just like custom server controls. So, if you are creating a bunch of controls for redistribution to customer sites and/or SharePoint sites why don't you just create Web Par...

Custom Server Control Made of Custom Controls?
I'm giving myself a crash course in custom server controls, and I have a quick general question. Can I have a custom server control that is composed of other server controls I created. I'm pretty sure the answer is yes, but I want to be positive. Yes Shows how to combine existing controls into a new control using class composition. -ron Thanks! ASP.NET so rocks! Making page components extensible objects is such a great idea! I love it....

How to render a repeater control in the custom server control?
 How to render a repeater control in the custom server  control because there is a lot of element inside the repeater control? My code is as follows: <div> <asp:Repeater ID="rptFields" runat="server"> <HeaderTemplate> <table> </HeaderTemplate> <ItemTemplate> <tr> <td><%# Eval("Prompt") %>:</td> <td><asp:PlaceHolder ID="plControl" runat="server" /> <input type="...

Using a server control in the rendering a custom control
Hi. I have a custom control that overrides the Render method to draw itself.  Is it possible to use a server control (asp:Image, wwHoverPanel, etc.) inside such a custom control or would I have to rewrite my custom control as a composite control? I'd like to do something something like:protected override void Render(HtmlTextWriter w) { w.RenderBeginTag(HtmlTextWriterTag.Table); w.RenderBeginTag(HtmlTextWriterTag.Tr) w.RenderBeginTag(HtmlTextWriterTag.Td) // somehow place asp:Label here w.RenderEndTag(); // column w.RenderEndTag(); // row ...

How to Render controls within an UpdatePanel in a Custom Server Control
Hi,Im writting a CompositeControl that contains a few UpdatePanels (TabContainer with an UpdatePanel on each TabPanel to make Tab control panels load "on-demand"). I want to control the renderring of the controls within the UpdatePanel's ContentTemplateContainer.How should I implement the render method of my CompositeControl?Should I use a custom UpdatePanel (inherit from UpdatePanel and override the RenderContents method)? is there a simpler solution? (because I need a different "render" for each tab panel....)Thanks Tal88 Hi, I want to control the renderring o...

Custom Server Control With Child Control
All, I am currently putting together a very simple control. The new control outputs a table with two rows. The top row contains a heading and the bottom row will contain any other content. The control as it stands works perfectly well and I can place text into the content row no problem. Now, to the problem. Once I'd completed the control I figured it would be neat to enable the developer to add controls directly into the bottom row (content row) of the outputted table. As you probably know the WebControl class has a Controls collection which the developer can use to add any other...

Custom Server Control with Child Controls
I have a custom server control <xx.Parent... /> which parses custom child controls <xx.Child... />. In Visual Studio 2008, IntelliSense shows me both when I start typing my control namespace. How can I prevent the child control from showing up in IntelliSense  unless I'm adding it within the parent tags?Thanks. --Rudy...

Custom Control within a Control Control
I am developing a custom controls that will render headers for different web sites. Within these controls, I want to place another custom control that will change the language. I created the language control and had it implement IPostBackDataHandler. This control works fine if I drag it on a new web form, but if I tell a header custom control to render it problems occur. The Language Selector custom control does not have a Page member anymore and the event handlers do not work. Does anyone have any experience with doing something similiar? Anyone have any suggestions? Thanks, ...

custom server control deployed for multiple site on server
Please let me know if this is the wrong spot to be asking this. I'm building a dynamic CMS solution where one set of code will host multiple sites and content will be based on the DB.  Each site will have some specific information for that site and a admin site where they control the content. Very similar to a standard CMS solution.  Where I think this is different is most of the content will be custom server controls that will act like widgets on the site.  Client will be able to place them where they want from the admin and it will save this to the db.  My pr...

handling events for controls in custom server control
Hi,     I am having a problem in using server controls in ASP.Net, with C#.  I am trying to create a server control which contains 2 other server controls that I created (Called MyImageButton).  MyImageButton extends the standard ImageButton with some other properties & methods that I needed.  It therefore also has the 'OnClick' event.  From the original server control, I would like to handle the Click event for these 2 image buttons in the same server control.  Basically, this server control will show 2 images, ascending and descendin...

Adding controls to a Custom DataGrid Server Control
Edited by SomeNewKid. Please post code between <code> and </code> tags. I'm working on creating my own customized datagrid control. I've created a class which inherits "System.Web.UI.WebControls.DataGrid" and when I add my new datagrid control library to my project it seems to work nicely. Now I want to add some submit buttons to appear at the bottom of my datagrid control. How do I do this? Sorry, I'm a bit of a newbie at server controls. Here's what I've tried: Public Class UberDataGrid Inherits DataGrid Private MyButton As Button ...

Web resources about - Custom Server Control to render multiple Controls -

Multiple sequence alignment - Wikipedia, the free encyclopedia
A multiple sequence alignment (MSA) is a sequence alignment of three or more biological sequences , generally protein , DNA , or RNA . In many ...

Man charged with murder of 21yo found on road in Tewantin with multiple stab wounds
Police charge a man with the murder of a 21-year-old man found lying on a road with multiple stab wounds to his chest.

Multiple shots fired at Atlanta mall -
Multiple shots were fired Saturday evening in a suburban Atlanta mall, prompting a frantic rush by shoppers to evacuate.

Nigeria: Over 70 Feared Killed in Borno, Adamawa Multiple Blasts
More than 70 people were feared killed in multiple bomb attacks believed to have been carried out by Boko Haram militants and their agents in ...

Facebook is testing multiple topic-based News Feeds for mobile devices
... the information you want to see at the appropriate times. According to the screenshots taken by Jason Stein, Facebook looks to be testing multiple, ...

Munich Police: Islamic State Planned New Year’s Eve Attack with Multiple Suicide Bombers
Munich police warned of a “serious, imminent threat” by Islamic State group suicide bombers wanting to commit an attack on New Year’s Eve.

An insanely high percentage of people — about 42% — are seeing "Star Wars: The Force Awakens" multiple ...
With the enormous box office sales "Star Wars: The Force Awakens" is generating, it's a good bet that many people are going back numerous times ...

Miami teen shot multiple times at grandma's home
The victim reportedly remains in the hospital as police continue to search for the suspect

Gov. Jerry Brown pardoned Robert Downey Jr. for his multiple crimes in the ’90s
I’m old enough to remember when Robert Downey Jr. was an utter mess. Back in the ‘90s, I lost count of how many times he was arrested, how many ...

Gas tank explodes at plant in Nigeria; multiple fatalities reported
CNN Gas tank explodes at plant in Nigeria; multiple fatalities reported CNN Kano, Nigeria (CNN) An industrial gas tank exploded in southern ...

Resources last updated: 1/4/2016 10:13:04 AM