By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,420 Members | 1,117 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,420 IT Pros & Developers. It's quick & easy.

How does this code step

P: n/a
A custom server control containing a Button inherits from the
WebControl class. I want to give users the option to change the
BackColor of the Button. If this is the code in the ASPX page that uses
the custom server control (whose class name is 'MyCls') which has been
compiled into 'MyDLL.dll' using VBC

<%@ Register Assembly="MyDLL" Namespace="MyNS" TagPrefix="cc1" %>
<form runat="server">
<cc1:MyCls ID="cccls" BackColor="red" runat="server"/>
</form>

then this does not change the BackColor of the Button control. To
change the BackColor of the Button, the BackColor property of the
Button control has to be overridden like this:

Namespace MyNS
Public Class MyCls : Inherits WebControl
Private strBackColor As System.Drawing.Color

Public Overrides Property BackColor() As System.Drawing.Color
Get
BackColor = strBackColor
End Get
Set(ByVal value As System.Drawing.Color)
strBackColor = value
End Set
End Property

Protected Overrides Sub CreateChildControls()
MyBase.CreateChildControls()
Dim btn1 As Button

btn1 = New Button
btn1.ID = "btn1"
btn1.BackColor = strBackColor
Me.Controls.Add(btn1)

ChildControlsCreated = True
End Sub
End Class
End Namespace

The ASPX code shown at the beginning will now change the BackColor of
the Button to red.

What I would like to know is when the compiler encounters
BackColor="red" in the ASPX code, how does the code flow after that? In
other words, which line first gets executed in the VB class file &
subsequently how does the code step from one line to the other in the
VB class file?

I don't have Visual Web Developer 2005 installed in my m/c which is why
I am asking this question.

Nov 5 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.