request for clarification

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
"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?
 
could you show me some general syntax on how to subscribe to a button event
when the button is in a WebUserControl?
 
Back
Top