473,387 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Inheriting System.UI.ControlCollection for a WebControl - FindControl doesn't work???

Here's the situation...Context - Using an Inherited WebControl object as a
base for server custom controls.

In a web custom control, whenever I create a child control and add it to the
Controls class, it takes 3 lines of code.

Example:

Dim TextBox as System.Web.UI.WebControls.TextBox
1..TextBox = New System.Web.UI.WebControls.TextBox
2..TextBox.ID = "myTextBox"
3..Controls.Add(TextBox)

I would like to overload the Controls object in WebControl to do this in one
line of code.

Controls.Add(New System.Web.UI.WebControls.TextBox, "myTextBox")

HOWEVER...

I don't think I've got everything glued together. For example: FindControl
doesn't return any controls that exist in my custom object. It is still
looking at myBase.Controls (I think). If I need to override FindControl,
are there other methods that I need to override as well, or am I going down
the wrong path?

'sample code
Public Class MyControl

Inherits CompositeWebControl

Protected Overrides Sub CreateChildControls()
Controls.Add(New System.Web.UI.WebControls.TextBox, "myTextBox")

End Sub

Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)
'breaks on this method - FindControl returns Nothing

FindControl("myTextBox").RenderControl(writer)

End Sub

End Class
Option Explicit On
Option Strict On

'inherited WebControl - use as a base for new WebControls

Public Class CompositeWebControl
Inherits System.Web.UI.WebControls.WebControl

Implements System.Web.UI.INamingContainer

Private mobjControls As WebControlCollection

Protected Overrides Function CreateControlCollection() As
System.Web.UI.ControlCollection

If (mobjControls Is Nothing) Then

mobjControls = New WebControlCollection(Me)

End If

Return CType(mobjControls, System.Web.UI.ControlCollection)

End Function

<System.ComponentModel.Browsable(False)> _

Public Shadows ReadOnly Property Controls() As WebControlCollection

Get

Me.CreateControlCollection()

Me.EnsureChildControls()

Return mobjControls

End Get

End Property

End Class

'custom ControlCollection that has an overloaded Add method...

Public Class WebControlCollection
Inherits System.Web.UI.ControlCollection

Sub New(ByVal owner As System.Web.UI.Control)

MyBase.New(owner)

End Sub

Public Overloads Sub Add(ByVal child As System.Web.UI.Control, ByVal ID
As String)

child.ID = ID

Me.Add(child)

End Sub

End Class

Nov 18 '05 #1
0 1740

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ivan Demkovitch | last post by:
Hi! I posted question while ago with no reply.. Here is wat I do: I have website with 1 page (pgracing.com) Each block/module is a control - .ascx. In one of them I dynamically create...
9
by: kw | last post by:
What is the proper way to get the element ID for a client script? For example, suppose in the WebControl: TextBox t=new TextBox; t.ID=this.ClientID+"X"; .... Then elsewhere we want to access...
10
by: tshad | last post by:
I have a problem setting the background color of textbox on the fly. I tried using: applicantID.backcolor = "F6F6F6" and applicantID.backcolor = "#F6F6F6"
1
by: DanielSchaffer | last post by:
I am trying to create a class that inherits fromControlCollection, but I am getting the compile error "Nooverload for method 'ControlCollection' takes '0' arguments",and VS highlights the constructor...
3
by: Alex Satrapa | last post by:
There's some mention in the (old!) documentation that constraints such as foreign keys won't include data from inheriting tables, eg: CREATE TABLE foo ( id SERIAL PRIMARY KEY ); CREATE TABLE...
9
by: Dominique | last post by:
I'm trying to create a C# composite control and have inherited from UserControl. This new control contains 9 buttons with images on them ( no text ). Firstly, what is the best way to expose...
2
by: Daves | last post by:
code in a webcontrol's Page_Load event wants to grab value of a TextBox in the parent page; (TextBox) _textBox = (TextBox) this.Page.FindControl("TB_TextBox1"); string _value = _textBox.Text; ...
0
by: Jose Fernandez | last post by:
Hello First of all, excuse my english We all know that in a normal page with codebehind we add a dropdownlist control and we bind() it in the (!ISPOSTBACK), so, we don't need to go to database...
0
by: Gursharan | last post by:
Hi, I get this error after I did a load test on my website (500 constant user load in team system for 35 minutes). This error is logged after about 1 minute of load testing and is logged every...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.