How does this code step

R

rn5a

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.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top