request for clarification

G

Guest

hey all,
below is an excerpt from an article i'm currently reading. the article is
about using WebUserControls and encapsulation.

"Although it is possible to subscribe to the button click event from the
containing page, doing so would break some of the object oriented rules of
encapsulation. A better idea is to publish an event in the user control to
allow any interested parties to handle the event. "

What does it mean to subscribe to the button click event?

thanks,
rodchar
 
T

Teemu Keiski

It means that you have a handler method which is called when Button is
clicked. For example:

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Click
me" />

'server-side code
Protected Sub Button1_Click(sender As Object,e As EventArgs)
'Called when Button is clicked
End Sub

This essentially means that Button1_Click method is called when Button
raises its Click event, to put it other words, you have subscribed on page
to the Button's Click event, that is to get notified when the Button is
clicked. The subscription is that Button1_Click method will be called.

The pattern more technically relies on the concept of events and delegates,
something you can read in documentation.
http://msdn2.microsoft.com/en-us/library/17sde2xt(VS.80).aspx
 
G

Guest

"Although it is possible to subscribe to the button click event from the
containing page"

What is the containing page? is that the aspx page?
 
G

Guest

could you show me some general syntax on how to subscribe to a button event
when the button is in a WebUserControl?
 

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,995
Messages
2,570,230
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top