Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
What is better?
Message
De
07/04/2008 22:33:43
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Versions des environnements
OS:
Windows XP
Database:
MS SQL Server
Divers
Thread ID:
01308825
Message ID:
01308913
Vues:
12
This message has been marked as a message which has helped to the initial question of the thread.
It depends on what you're actually trying to do, as Viv mentioned, it may not be too clear from your description of what you're trying to accomplish.

>Is it ok from one control event call another control's event or it's better to have both call their own but reference an extra common function?

When I first read your question, it sounded like you wanted code in one control's event handler to call the event handler of another control. Something like this:
private void MyTextBoxOne_Validated(object sender, System.EventArgs e)
{
	this.MyTextBoxTwo_Validated(sender, e);
	// Maybe do some other stuff
}
private void MyTextBoxTwo_Validated(object sender, System.EventArgs e)
{
	// Do some stuff
}
This is obviously a no-no and I think Al thought your question was this, hence his answer.

But, then, in your reply to Viv:

>Or how would you approach the problem of having same code executed for the same event in different objects?

It seems to me what you're actually asking is not what it seemed from your first question. Anyway, there's nothing wrong with having one event handler take care of an event for more than one control. Say I have several TextBoxes on my Form, but in the Validated event of each one, I want to do the exact same thing.

So, I'd have one MyTextBoxValidatedHandler, and each TextBox would have a delegate for that event handler. Something like this:
this.MyTextBoxOne.Validated()   += new EventHandler(this.MyTextBoxValidatedHandler);
this.MyTextBoxTwo.Validated()   += new EventHandler(this.MyTextBoxValidatedHandler);
this.MyTextBoxThree.Validated() += new EventHandler(this.MyTextBoxValidatedHandler);
And the event handler would be the usual:
private void MyTextBoxValidatedHandler(object sender, System.EventArgs e)
{
	// Do some stuff
}
HTH,
~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform