PC Review


Reply
Thread Tools Rate Thread

Control / Property. Going crazy here.

 
 
shapper
Guest
Posts: n/a
 
      28th May 2007
Hello,

I have a class where I created various controls.
One of the controls have a property which is a generic list of
WebControl.

Then in web site page I have something like:
Dim a As New MyNamespace.ListItem
a.WebControls.Add(tbName)
a.WebControls.Add(lLabel)
Response.Write(a.WebControls.Count) >>> This returns 0!

When the control renders I can only see its start and end tags.
The controls that I added to it are not rendered into the page.
In fact they seem to not being added to the WebControls property.
(Count returns 0)

I am on this for 2 days. I have no idea what is going on. I tried
everything I could think of!
I think the problem might be in my control property WebControls.

Please, could someone help me out?

Here is my control code:

<DefaultProperty("ID"), ToolboxData("<{0}:Item runat=server></
{0}:Item>")> _
Public Class ListItem
Inherits WebControl
Implements INamingContainer

<Bindable(True), Category("Settings"), DefaultValue(""),
Localizable(True)> _
Property WebControls() As Generic.List(Of WebControl)
Get
If CStr(ViewState("WebControls")) Is Nothing Then
Return New Generic.List(Of WebControl)
Else
Return ViewState("WebControls")
End If
End Get
Set(ByVal Value As Generic.List(Of WebControl))
ViewState("WebControls") = Value
End Set
End Property ' WebControls

' CreateChildControls
Protected Overrides Sub CreateChildControls()

' Add controls to item
For Each control As WebControl In Me.WebControls
MyBase.Controls.Add(control)
Next ' control

' Create child controls
MyBase.CreateChildControls()
Me.ChildControlsCreated = True

End Sub ' CreateChildControls

End Class ' List

Thanks,
Miguel

 
Reply With Quote
 
 
 
 
shapper
Guest
Posts: n/a
 
      29th May 2007
On May 28, 7:38 pm, shapper <mdmo...@gmail.com> wrote:
> Hello,
>
> I have a class where I created various controls.
> One of the controls have a property which is a generic list of
> WebControl.
>
> Then in web site page I have something like:
> Dim a As New MyNamespace.ListItem
> a.WebControls.Add(tbName)
> a.WebControls.Add(lLabel)
> Response.Write(a.WebControls.Count) >>> This returns 0!
>
> When the control renders I can only see its start and end tags.
> The controls that I added to it are not rendered into the page.
> In fact they seem to not being added to the WebControls property.
> (Count returns 0)
>
> I am on this for 2 days. I have no idea what is going on. I tried
> everything I could think of!
> I think the problem might be in my control property WebControls.
>
> Please, could someone help me out?
>
> Here is my control code:
>
> <DefaultProperty("ID"), ToolboxData("<{0}:Item runat=server></
> {0}:Item>")> _
> Public Class ListItem
> Inherits WebControl
> Implements INamingContainer
>
> <Bindable(True), Category("Settings"), DefaultValue(""),
> Localizable(True)> _
> Property WebControls() As Generic.List(Of WebControl)
> Get
> If CStr(ViewState("WebControls")) Is Nothing Then
> Return New Generic.List(Of WebControl)
> Else
> Return ViewState("WebControls")
> End If
> End Get
> Set(ByVal Value As Generic.List(Of WebControl))
> ViewState("WebControls") = Value
> End Set
> End Property ' WebControls
>
> ' CreateChildControls
> Protected Overrides Sub CreateChildControls()
>
> ' Add controls to item
> For Each control As WebControl In Me.WebControls
> MyBase.Controls.Add(control)
> Next ' control
>
> ' Create child controls
> MyBase.CreateChildControls()
> Me.ChildControlsCreated = True
>
> End Sub ' CreateChildControls
>
> End Class ' List
>
> Thanks,
> Miguel


Please, anyone?

My full code is as follows:

1
2 <DefaultProperty("ID"), ToolboxData("<{0}:ListItem
runat=server></{0}:ListItem>")> _
3 Public Class ListItem
4 Inherits WebControl
5 Implements INamingContainer
6
7 <Bindable(True), Category("Settings"), DefaultValue(""),
Localizable(True)> _
8 Property WebControls() As Generic.List(Of WebControl)
9 Get
10 If CStr(ViewState("WebControls")) Is Nothing Then
11 Return New Generic.List(Of WebControl)
12 Else
13 Return ViewState("WebControls")
14 End If
15 End Get
16 Set(ByVal Value As Generic.List(Of WebControl))
17 ViewState("WebControls") = Value
18 End Set
19 End Property ' WebControls
20
21 Protected Overrides Sub CreateChildControls()
22
23 ' Add controls to item
24 For Each control As WebControl In Me.WebControls
25 MyBase.Controls.Add(control)
26 Next ' control
27
28 ' Create child controls
29 MyBase.CreateChildControls()
30 Me.ChildControlsCreated = True
31
32 End Sub ' CreateChildControls
33 End Class ' ListItem
34
35 ' List
36 <DefaultProperty("ID"), ToolboxData("<{0}:List runat=server></
{0}:List>")> _
37 Public Class List
38 Inherits WebControl
39 Implements INamingContainer
40
41 ' Items ...
42 <Bindable(True), Category("Settings"), DefaultValue(""),
Localizable(True)> _
43 Property Items() As Generic.List(Of ListItem)
44 Get
45 If CStr(ViewState("Items")) Is Nothing Then
46 Return New Generic.List(Of ListItem)
47 Else
48 Return ViewState("Items")
49 End If
50 End Get
51 Set(ByVal Value As Generic.List(Of ListItem))
52 ViewState("Item") = Value
53 End Set
54 End Property ' Items
55
56 ' CreateChildControls
57 Protected Overrides Sub CreateChildControls()
58
59 ' Add controls to item
60 For Each item As ListItem In Me.Items
61 MyBase.Controls.Add(item)
62 Next ' item
63
64 ' Create child controls
65 MyBase.CreateChildControls()
66 Me.ChildControlsCreated = True
67
68 End Sub ' CreateChildControls
69
70 End Class ' List


Thanks,
Miguel

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Property. What am I doing wrong? Going crazy ... shapper Microsoft ASP .NET 10 3rd Nov 2007 07:42 AM
Exposing control property as list of items on property sheet... Charlie@CBFC Microsoft Dot NET Framework Forms 0 17th Nov 2006 05:31 PM
can a custom control have an image property that can be set in design time from the property browser? news.austin.rr.com Microsoft Dot NET Compact Framework 3 3rd Mar 2005 02:08 AM
Adding code property to control property window NuBBeR Microsoft C# .NET 1 7th Oct 2004 05:15 PM
How to throw and catch an exception in the property set when property is bound to a wiform control Keith Roe Microsoft Dot NET Framework 2 4th Dec 2003 05:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:50 AM.