Design-Time Attributes of Custom Controls
page 2 of 6
by . .
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 30186/ 67

The Base Control

The base control

The control that will be used for this article will the same one that we used in Posting Back in Custom Controls (Single Highlight). However, first we will make some changes to it -

When you inherit from System.Web.UI.WebControls.WebControl you automatically get a bunch of properties that by default already show up in VS.NET (including BackColor, BorderStyle, Font, CssClass etc.) which you can chose to implement of not (you could also inherit from System.Web.UI.Control and not get any of those properties) . In our new highlighting class (VSHighlight) we will be using some of these properties.

We are also going to need some additional properties that aren't initially provided by the base class (eg. the Text of the control and the alternating background color).

Below is the new class -

Public Class VSHighlight
Inherits
System.Web.UI.WebControls.WebControl
Implements
IPostBackEventHandler

Private pvText As String
Private
tColor As System.Drawing.Color = System.Drawing.Color.Black
Private
bgColoron As System.Drawing.Color = System.Drawing.Color.LimeGreen

Public
Property TextColor() As System.Drawing.Color

Get

Return
tColor

End
Get
Set
(ByVal Value As System.Drawing.Color)
tColor = Value

End
Set
End
Property

Public Property BackColor_On() As System.Drawing.Color
Get

Return
bgColoron

End
Get
Set
(ByVal Value As System.Drawing.Color)
bgColoron = Value

End
Set
End
Property

Public Property Text() As String
Get

Return
pvText

End
Get
Set
(ByVal Value As String)
pvText = Value

End
Set
End
Property

Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
output.AddAttribute("border", "1")
output.AddAttribute("onClick", Page.GetPostBackEventReference(Me))

If
Viewstate(ID & "click") = 1
Then
output.AddAttribute("bgcolor", BackColor_On.ToKnownColor.ToString())

Else

output.AddAttribute("bgcolor", MyBase.BackColor.ToKnownColor.ToString())

End
If
output.AddStyleAttribute("cursor", "hand")
output.AddStyleAttribute("border-width", MyBase.BorderWidth.Value.ToString())
output.AddStyleAttribute("border-color", MyBase.BorderColor.ToKnownColor.ToString())
output.AddStyleAttribute("height", "5")
output.AddStyleAttribute("border-style", MyBase.BorderStyle.ToString())
output.RenderBeginTag("table")
output.RenderBeginTag("tr")
output.RenderBeginTag("td")
output.AddAttribute("face", "Arial")
output.AddAttribute("size", "4")
output.RenderBeginTag("font")
output.RenderBeginTag("b")
Page.Response.Write(Text)
output.RenderEndTag()
output.RenderEndTag()
output.RenderEndTag()
output.RenderEndTag()
output.RenderEndTag()

End
Sub

Public Sub RaisePostBackEvent(ByVal eventargs As String) _
Implements
IPostBackEventHandler.RaisePostBackEvent

If
ViewState(ID & "click") = 1
Then
ViewState(ID & "click") = 0

Else

ViewState(ID & "click") = 1

End
If
End
Sub

End Class


View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2021 ASPAlliance.com  |  Page Processed at 2021-02-25 11:23:23 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search