Event

Event

am 12.01.2008 04:18:21 von Shapper

Hello,

I created a custom control where I need to have an event named
Submitted.
This event should have 3 arguments: Name, Type, Time

And I would catch it has follows:

Public Sub MyControl_Submited(ByVal sender As Object, ByVal e As
MyControlEventArgs) Handles MyControl.Submited

Response.Write(e.Name)
Response.Write(e.Type)
Response.Write(e.Time)

End Sub

So I would like to do this as it is usually done in Asp.Net, for
example, in a button.

How can I create such an event (MyControlEventArgs) and fire it?

Thanks,
Miguel

RE: Event

am 14.01.2008 01:19:01 von mily242

Hi there,

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)


--
Milosz


"shapper" wrote:

> Hello,
>
> I created a custom control where I need to have an event named
> Submitted.
> This event should have 3 arguments: Name, Type, Time
>
> And I would catch it has follows:
>
> Public Sub MyControl_Submited(ByVal sender As Object, ByVal e As
> MyControlEventArgs) Handles MyControl.Submited
>
> Response.Write(e.Name)
> Response.Write(e.Type)
> Response.Write(e.Time)
>
> End Sub
>
> So I would like to do this as it is usually done in Asp.Net, for
> example, in a button.
>
> How can I create such an event (MyControlEventArgs) and fire it?
>
> Thanks,
> Miguel
>