JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Adding Events to Web User Controls

Adding an event to a Web user control is not difficult; you just need to declare the event and the parameters you want passed to the event's handler procedures. For more information, see "Creating Events" in Chapter 11.

For example, in the WebUserControls example discussed in the In Depth section of this chapter, we added an event named TextModified to the control:

    Public Event TextModified(ByVal NewText As String)

This event occurs when the text in the Web user control is modified, which happens in the SetText method (see the previous topic), so we can use the RaiseEvent method in the SetText method to make this event occur:

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

For more on how this works, including how to handle this new event in code when it occurs, see the discussion of the WebUserControls example in the In Depth section of this chapter.

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor