deriving from textbox control

L

Lisa Calla

Hi,
I'm trying to control the foreground and background colors of a textbox. I
hate that light gray foreground when the textbox.enabled=false. I've tried
to derive a control from the textbox, but I get the following error when
trying to run a page with the control on it. wc is the name of my class,
and exp is the name of my project.

Parser Error Message: 'exp.wc' is not a valid base class because it does not
extend class 'System.Web.UI.UserControl'.

Source Error:


Line 1: <%@ Control Language="vb" AutoEventWireup="false"
Codebehind="wc.ascx.vb" Inherits="exp.wc"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>

And here's the code:

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

Public Class wc
Inherits System.Web.UI.WebControls.TextBox

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

'Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' 'Put user code to initialize the page here
'End Sub

Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
If Me.Enabled Then
Me.BackColor = Color.FromName("White")
Else
Me.BackColor = Color.FromName("LightGray")
End If
Me.ForeColor = Color.FromName("Black")
End Sub
End Class

Can anyone explain to me why I get this error?
 
S

Sam Fields

TextBox is a WebControl, whereas a UserControl is an object all its own..
If you're using a UserControl, you need to add a TextBox TO the UserControl,
rather then inheriting it.

Your other option is to create a web custom control that inherits the
textbox, and then you can use an @Register directive to include it on an
aspx page.
 
M

Matt Berther

Hello Lisa,

Gosh... wouldnt the easier alternative be to use CSS?

input {
border: 1px solid black;
}
 
L

Lisa Calla

Ah, thanks for clearing that up.

Sam Fields said:
TextBox is a WebControl, whereas a UserControl is an object all its own..
If you're using a UserControl, you need to add a TextBox TO the
UserControl,
rather then inheriting it.

Your other option is to create a web custom control that inherits the
textbox, and then you can use an @Register directive to include it on an
aspx page.
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top