asp.net c#通用事件处理例程 [英] asp.net c# generic event handling routine

查看:74
本文介绍了asp.net c#通用事件处理例程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在asp.net c#中实现一个通用的事件处理例程,它将任何控制作为输入并执行所需的操作?这是如何为具有类似操作的控件实现ROUTINES?

How to implement a generic event handling routine in asp.net c# that takes any control as an input and performs the required operation?That is how to implement ROUTINES for controls having similar operations?

推荐答案

每个事件都是通用的(除了自定义EventArgs的专用事件,甚至它们都可以使用基本版本),因为它们提供发送者 object参数,它是引发事件的类(或本例中的Control)和带有任何详细信息的 e EventArgs参数。所以你可以(理论上,我讨厌在实践中这样做)将你的所有事件发送到一个处理程序,并在其中解决处理程序应该用它做什么。



如果你期望许多不同的Control类型使用相同的处理程序,可能是处理事情的一种糟糕方式 - 但这是可能的。
Every event is generic already (barring only the "specialised" ones with custom EventArgs, and even they will work with the base version) since they provide a sender object parameter which is the class (or Control in this case) that raised the event and an e EventArgs parameter with any details. So you can (in theory, I'd hate to do it in practice) send all your Events to a single handler, and sort out within that what the handler is supposed to do with it.

Probably be a poor way to handle things if you are expecting a number of different Control types to use the same handler though - but it is possible.


这篇关于asp.net c#通用事件处理例程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆