Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > subclassing web controls

Thread Tools

subclassing web controls

Posts: n/a
I am trying to use as a guide an example in the VBNET Developer's Guide
by McManus and Kinsman (ch 10,) on Subclassing Existing Server Controls.
Rather than create a User Control (ascx) or a Composite Control, I want
to make a simple extension to the CheckBoxList control class using
inheritance. The inherited version of the control returns the sum of the
values checked, and allows me to assign an integer to the control's Bits
property and then the control will figure out which items to check. [The
values of the list items are actually bits (2^0, 2^1, 2^2, 2^3, etc).
See code below.]

I created the class in my project (which had some forms and other
classes in it) and compiled the specific class file into a DLL as

vbc CustomControls.vb /t:library /out:CustomControls.dll
/r:System.dll /r:System.Web.dll

I copied the DLL into the \bin directory and in my project I added a
reference to the compiled DLL. Then I added a Register Directive to my
aspx form:

<%@ Register TagPrefix="timo" namespace="MyCustomControls"
Assembly="CustomControls" %>

And then I added an instance of the inherited control to my form's HTML:

<timo:BitCheckList id='BitCheckList1' runat='server' />

But I get the following error message when I run it:

The base class includes the field 'BitCheckList1', but its type
(MYPROJ.MyCustomControls.BitCheckList) is not compatible with the type
of control (MyCustomControls.BitCheckList).

If I add a Tagname="MyCustomControls" to the register directive, I get a
different error, namely that the directive lacks a SRC attribute (i.e.
it is looking for the .ascx file). But I'd like to avoid the
limitations of user controls if that's possible by inheriting directly
from the CheckBoxList class. I'd be grateful for explanations of what
the first error means and how it should be fixed in my code.

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace MyCustomControls
Public Class BitCheckList
Inherits System.Web.UI.WebControls.CheckBoxList

Public Sub New()
End Sub

Public Property Bits() As Integer
Return GetBits()
End Get
Set(ByVal Value As Integer)
End Set
End Property
Private Function GetBits() As Integer
Dim LI As System.Web.UI.WebControls.ListItem
Dim temp As Integer = 0
For Each LI In Me.Items
If LI.Selected Then
temp += LI.Value
End If
Return temp
End Function
Private Function SetBits(ByVal v)
Dim LI As System.Web.UI.WebControls.ListItem
For Each LI In Me.Items
LI.Selected = ((v And LI.Value) = LI.Value)
End Function

End Class
Reply With Quote
Posts: n/a
Following up on my own question. The problem was caused by the fact that
the source code for the inherited control was part of the current
project. The reference to the external DLL doesn't disambiguate things
at compile time.
Reply With Quote

Thread Tools

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
Using Web.config's <system.web><pages><controls><add /></controls></pages></system.web> To Register UserControls Nathan Sokalski ASP .Net 5 01-10-2007 10:50 AM
Using Web.config's <system.web><pages><controls><add /></controls></pages></system.web> To Register UserControls Nathan Sokalski ASP .Net Web Controls 4 12-21-2006 02:50 AM
Using Web.config's <system.web><pages><controls><add /></controls></pages></system.web> To Register UserControls Nathan Sokalski ASP .Net Building Controls 4 12-21-2006 02:50 AM
Subclassing Controls TheStripe ASP .Net 2 09-27-2004 01:17 PM
Subclassing from System.Web.UI.Page - Designer Error =?Utf-8?B?Q2h1Y2sgSGFlYmVybGU=?= ASP .Net 1 02-20-2004 05:05 PM