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

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

am 12.01.2008 18:59:43 von 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

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

am 14.01.2008 01:06:01 von mily242

Howdy,

http://www.ondotnet.com/pub/a/dotnet/excerpt/progaspdotnet_1 4/index1.html?page=4

--
Milosz


"shapper" wrote:

> 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
>

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

am 14.01.2008 01:22:00 von mily242

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)
--
Milosz


"Milosz Skalecki [MCAD]" wrote:

> Howdy,
>
> http://www.ondotnet.com/pub/a/dotnet/excerpt/progaspdotnet_1 4/index1.html?page=4
>
> --
> Milosz
>
>
> "shapper" wrote:
>
> > 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
> >