Add Click Event to my WebCustomControl?

  • Thread starter Thread starter Lars Netzel
  • Start date Start date
L

Lars Netzel

I have made a pretty small and simple webCustomerControl that basically just
renders some HTML tables... I want parts of this to be clickable to fire off
a "Click Event" that you can use as a developer, how do I do this?

best regards/
Lars Netzel
 
Lars Netzel said:
I have made a pretty small and simple webCustomerControl that basically
just renders some HTML tables... I want parts of this to be clickable to
fire off a "Click Event" that you can use as a developer, how do I do this?

Take a look at some of the following MSDN links:

Events in ASP.NET Server Controls
(http://msdn.microsoft.com/library/d...pguide/html/cpconeventsinwebformscontrols.asp)


Processing Postback Data
(http://msdn.microsoft.com/library/d...receivingpostbackdatachangednotifications.asp)



Capturing Postback Events
(http://msdn.microsoft.com/library/d.../cpconreceivingpostbackeventnotifications.asp)



Bubbling an Event
(http://msdn.microsoft.com/library/d...us/cpguide/html/cpconbubblingcommandevent.asp)



Generating Client-Side Script for Postback
(http://msdn.microsoft.com/library/d...eneratingclient-sidejavascriptforpostback.asp)



John Saunders
 
Hi Lars!

CustomControl is basicaly Class and classes can have events. If you have
worked with properties in ASCX you know, that you have to publish properties
from your control and so is with events:

part of x.ASCX.vb file:
' Declare custom event
Public Event myButtonClick(ByVal sender As System.Object, ByVal e As
System.EventArgs)
' Handel event on ASCX
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'Raise your event
RaiseEvent myButtonClick(Me, e)
End Sub

Then you have known issue by using this ascx on ASPX. Namely when you drag
ASCX control on your page Visual Studio .NET 2003 does not declare varibales,
so you have to do it by hand and then you can use your events:

part of code on x.ASPX.vb:
' First declare variable with the same name as ID of your web custom control
Protected WithEvents clickable1 As Clickable

' then you can use events
Private Sub clickable1_myButtonClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles clickable1.myButtonClick
Response.Write("Yeah")
End Sub

That's all. If you think that code is not readable enough I can send you
sample project.

Dusan Zupancic
 
Back
Top