Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Subclassing - i am getting better at this more help tho
Message
 
À
13/07/2004 13:19:49
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
00923810
Message ID:
00923865
Vues:
16
Bonnie,

AWESOME, this makes total sense now, i went to DevTeach and learnt some things about delegates and this ties in with that.

I will post my results.

Thanks Again Bonnie.

>Shawn,
>
>>I think this is what you were telling me to do?
>
>No, here's an example of what I'm trying to say.
>
>In your base button class, you need the following things:
>
>// First you must make a public EventHandler:
>public event EventHandler MyClick;
>
>// Then, in the base button's Click EventHandler, do this:
>this.OnMyClick(new EventArgs());
>
>// Lastly, this raises the MyClick event:
>protected virtual void OnMyClick(EventArgs e)
>{
>	if (MyClick != null)
>		MyClick(this, e);
>}
>
>Then, in your sub-classed button, you just set up the usual delegates and EventHandlers:
>
>this.MyButton.MyClick += new System.EventHandler(this.MyButton_MyClickHandler);
>
>private void MyButton_MyClickHandler(object sender, System.EventArgs e)
>{
>	bool lResult = this.Login_Click();
>	if (!lResult)
>		this.txtCompanyID.Focus();
>}
>
>
>However, this doesn't take care of the case where you might actually want to run the AuthenticateUser() method (as your base class button should do). So, a better idea (and I hope you're not further confused by this), is to have your base button actually fire off two events. Here's the Click EventHandler in the base button's class:
>
>public event EventHandler MyClick;
>public event EventHandler MyClickDoSomething;
>
>private void MyBaseButton_ClickHandler(object sender, System.EventArgs e)
>{
>    this.OnMyClick(new EventArgs());
>    this.OnMyClickDoSomething(new EventArgs());
>}
>
>One event actually does the default code, the other event simply raises the event.
>
>protected virtual void OnMyClickDoSomething(EventArgs e)
>{
>	if (MyClickDoSomething != null)
>	{
>		this.AuthenticateUser();
>
>		MyClickDoSomething(this, e);
>	}
>}
>protected virtual void OnMyClick(EventArgs e)
>{
>	if (MyClick != null)
>	{
>		MyClick(this, e);
>	}
>}
>
>If the sub-classed button (or the button on a form) has a delegate to the MyClickDoSomething event, then the default code (your AuthenticateUser() method in your case) will be executed as usual prior to the code in the sub-classed button's event handler. However, if you don't want the default code on the control to fire, you set a delegate to the other event instead (the MyClick()) thereby enabling the sub-classed button to do some code and the default (the AuthenticateUser()) will not get done.
>
>
>~~Bonnie
Shawn Dorion
Geo Sektor Dot Com
Website: http://www.geosektor.com

Web Hosting Plans
Visit : http://WebHosting.Applications4u.com/
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform