User control based on System.Web.UI.WebControls.Label (VB) : WebControl « User Control and Master Page « ASP.Net

ASP.Net
1. ADO.net Database
2. Ajax
3. Asp Control
4. Collections
5. Components
6. Data Binding
7. Development
8. File Directory
9. HTML Control
10. Language Basics
11. Login Security
12. Mobile Control
13. Network
14. Page
15. Request
16. Response
17. Server
18. Session Cookie
19. Sitemap
20. Theme Style
21. User Control and Master Page
22. Validation by Control
23. Validation by Function
24. WebPart
25. WPF
26. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.Net » User Control and Master Page » WebControl 
User control based on System.Web.UI.WebControls.Label (VB)


<%@ Page language="VB" %>
<%@ Register TagPrefix="Control" Namespace="Control" Assembly="Control" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
  <head>
    <title>Extending Existing Web Controls</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">
      <Control:RainbowLabel text="This is a rainbow colored test string" runat="server" /><br/>
      <Control:RainbowLabel EnableRainbowMode="false" text="This is a test string" runat="server" />
    </form>
  </body>
</html>

File: Control.vb

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Namespace Control

    Public Class RainbowLabel
        Inherits System.Web.UI.WebControls.Label

        Public Property EnableRainbowMode() As Boolean
            Get
                If ViewState("EnableRainbowMode"Is Nothing Then
                    Return True
                Else
                    Return Boolean.Parse(CStr(ViewState("EnableRainbowMode")))
                End If
            End Get
            Set(ByVal Value As Boolean)
                ViewState("EnableRainbowMode"= Value
            End Set
        End Property

        Protected Overrides Sub Render(ByVal output As HtmlTextWriter)
            If EnableRainbowMode Then
                output.Write(ColorizeString([Text]))
            Else
                output.Write([Text])
            End If
        End Sub 'Render

        Private Function ColorizeString(ByVal input As StringAs String
            Dim output As New System.Text.StringBuilder(input.Length)
            Dim rand As Random = New Random(DateTime.Now.Millisecond)

            Dim As Integer
            For i = To input.Length - 1
                Dim red As Integer = rand.Next(0255)
                Dim green As Integer = rand.Next(0255)
                Dim blue As Integer = rand.Next(0255)

                output.Append("<font color=""#")
                output.Append(Convert.ToString(red, 16))
                output.Append(Convert.ToString(green, 16))
                output.Append(Convert.ToString(blue, 16))
                output.Append(""">")
                output.Append(input.Substring(i, 1))
                output.Append("</font>")
            Next i

            Return output.ToString()
        End Function 'ColorizeString
    End Class 'RainbowLabel
End Namespace

 
Related examples in the same category
1. SimpleControl extendsing System.Web.UI.WebControls.WebControl
2. SimpleControl extendsing System.Web.UI.WebControls.WebControl (C#)
3. User control based on System.Web.UI.WebControls.Label (C#)
4. Bindable user control (C#)
5. Bindable user control (VB)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.