JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Creating Web User Controls

Creating a Web user control is not difficult; just select the File|New|Project and choose the Web Control Library item, or select the Project|Add Web User Control menu item.

For example, we created a new Web user control in the WebUserControls example on the CD-ROM, as discussed in the In Depth section of this chapter. The Web user control we created supports a DisplayColor property, a SetText method, and a TextModified event; here's the code in the WebUserControl1.ascx.vb file in that project that supports the new control:

Public MustInherit Class WebUserControl1
    Inherits System.Web.UI.UserControl
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label

' Web Form Designer Generated Code...
    Private LabelColor As Color
    Public Event TextModified(ByVal NewText As String)

    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

    Property DisplayColor() As Color
            Return LabelColor
        End Get

        Set(ByVal Value As Color)
            LabelColor = Value
            Label1.BackColor = LabelColor
        End Set
    End Property

    Public Sub SetText(ByVal NewText As String)
        Label1.Text = NewText
        RaiseEvent TextModified(NewText)
    End Sub
End Class

For the details on this example, see the In Depth section of this chapter, as well as the next few topics.

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor