Control Event. Please, need some help. Thank You.

S

shapper

Hello,

I am creating a custom control and I need to define a custom event
with its own arguments.

I would like to use the ASP.NET standard way to do this, i.e:

Private Sub MyCustomControl_Submited(ByVal sender As Object, ByVal
e As MyCustomControlEventArgs) Handles mccTest.Submited
...
End Sub

Where "e" contains the arguments.

I created the following:

' SubmitedEventArgs
Public Class SubmitedEventArgs
Inherits EventArgs

Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property ' Name

Public Sub New(ByVal name As String)
Me.Name = name
End Sub ' New

End Class

And an handler:

' SubmitedEventHandler
Public Class SubmitedEventHandler

Public Delegate Sub SubmitedEventHandler(ByVal sender As Object,
ByVal e As SubmitedEventArgs)

End Class

Is this right?

And how can make my Custom Control to define, use and raise this
event?

Thanks,

Miguel
 
M

Milosz Skalecki [MCAD]

Actually, I managed to find a moment to prepare an example

Partial Class WebUserControl
Inherits System.Web.UI.UserControl

Protected Sub btn_Click(byval sender as Object, byval e as EventArgs)
Handles btn.Click

Dim e As New SubmitedEventArgs()

e.Time = DateTime.Now
e.Type = txtType.Text
e.Name = txtName.Text

OnSubmitted(e)
End Sub

Public Event Submitted As SubmitedEventHandler

Protected Overridable Sub OnSubmitted( _
ByVal e As SubmitedEventArgs)
RaiseEvent Submitted(Me, e)
End Sub

End Class

Public Class SubmitedEventArgs
Inherits EventArgs

Private _time As DateTime
Public Property Time() As DateTime
Get
Return _time
End Get
Set(ByVal value As DateTime)
_time = value
End Set
End Property

Private _name As String
Public Property Name() As String
Get
Return IIf(_name Is Nothing, String.Empty, _name)
End Get
Set(ByVal value As String)
_name = value
End Set
End Property

Private _type As String
Public Property Type() As String
Get
Return IIf(_name Is Nothing, String.Empty, _type)
End Get
Set(ByVal value As String)
_type = value
End Set
End Property

End Class

Public Delegate Sub SubmitedEventHandler( _
ByVal sender As Object, _
ByVal e As SubmitedEventArgs)
 

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,795
Messages
2,569,644
Members
45,358
Latest member
TreyTritt8

Latest Threads

Top