Inherits from Control, Yay, Inherits from WebControl, Nay....

A

Alex Nitulescu

Hi, I have the following in project "RaducuCustomControls":

Imports System.ComponentModel
Imports System.Web.UI

<DefaultProperty("Text"), ToolboxData("<{0}:Rotator1
runat=server></{0}:Rotator1>")> Public Class Rotator1
Inherits System.Web.UI.WebControls.WebControl

Public Items As New ArrayList()

Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)

Dim objRandom As New Random()
Dim intRanIndex As Integer
Dim objSelectedItem As RotatorItem1

If Items.Count > 0 Then
intRanIndex = objRandom.Next(Items.Count)
objSelectedItem = CType(Items(intRanIndex), RotatorItem1)
output.Write(objSelectedItem.Text)
End If
End Sub

Protected Overrides Sub AddParsedSubObject(ByVal obj As Object)

If TypeOf obj Is RotatorItem1 Then
Items.Add(obj)
End If
End Sub
End Class

<DefaultProperty("Text"), ToolboxData("<{0}:RotatorItem1
runat=server></{0}:RotatorItem1>")> Public Class RotatorItem1
Inherits System.Web.UI.WebControls.WebControl

Dim _text As String
Dim _color As String

<Description("The text of this item"), Bindable(True),
Category("Appearance"), DefaultValue("")> Property [Text]() As String
Get
Return _text
End Get

Set(ByVal Value As String)
_text = Value
End Set
End Property

<Description("The color in which the text will be rendered"),
Bindable(True), Category("Appearance"), DefaultValue("Black")> Property
[Color]() As String
Get
Return _color
End Get

Set(ByVal Value As String)
_color = Value
End Set
End Property

Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)

writer.AddAttribute("color", [Color])
writer.RenderBeginTag("font")
writer.Write([Text])
writer.RenderEndTag()
End Sub
End Class

I also have <Assembly: TagPrefix("RaducuCustomControls", "raducu")> in
AssemblyInfo.vb in "RaducuCustomControls". Therefore, I expect the following
code to run just fine:

<raducu:Rotator1 id="Rotator11" runat="server">
<raducu:RotatorItem1 id="RotatorItem11" text="One" color="red"
runat="server"></raducu:RotatorItem1>
<raducu:RotatorItem1 id="Rotatoritem12" text="Two" color="green"
runat="server"></raducu:RotatorItem1>
<raducu:RotatorItem1 id="Rotatoritem13" text="Three" color="blue"
runat="server"></raducu:RotatorItem1>
<raducu:RotatorItem1 id="Rotatoritem14" text="Four"
runat="server"></raducu:RotatorItem1>
</raducu:Rotator1>

However, I get

Type 'RaducuCustomControls.Rotator1' does not have a property named
'raducu:RotatorItem1'.

on <raducu:RotatorItem1 id="RotatorItem11" text="One" color="red"
runat="server"></raducu:RotatorItem1>.

If I change the Inherits in my custom control from Webcontrol to control, it
works, although I don't see the properties I'm interested in.

Please tell me, what am I missing here ?

Thank you, Alex.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,991
Messages
2,570,217
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top