什么是参数的目的,对象o和EventArgs的EA,在ddlChooseReport_Function(ASP.net)? [英] What is the purpose of the arguments Object o and EventArgs ea, in ddlChooseReport_Function (ASP.net)?

查看:161
本文介绍了什么是参数的目的,对象o和EventArgs的EA,在ddlChooseReport_Function(ASP.net)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,这种方法签名的ASP的宗旨是:

I'm curious as to the purpose of this method signature in ASP:

protected void ddlChooseReport_Function(Object sender, EventArgs e) 

由于方法体之后,它从来没有提到任何一个参数

because in the method body afterward, it never mentions either parameter

推荐答案

方法签名是为了与事件处理程序兼容进行接线的的一个事件一个事件处理程序。这是一个有点像实现一个接口。

The method signature has to be compatible with EventHandler in order to be wired up as an event handler for an event. It's a bit like implementing an interface.

只是因为特定的实现不发生使用它们并不意味着他们是无用的。例如,您可以使用相同的事件处理程序要连接许多控件的事件,并使用发件人参数区分它们 - 和其他信息的情况下可以通过传播在电子参数...虽然当它只是 EventArgs的,有没有那么的更可的传播。

Just because the particular implementation doesn't happen to use them doesn't mean they're useless. For example, you might use the same event handler to wire up events for many controls, and differentiate between them using the sender parameter - and additional information about the event can be propagated through the e parameter... although when it's just EventArgs, there isn't much more that can be propagated.

在.NET中的一般的事件处理程序委托类型(不是特定于ASP.NET)遵循使用对象发件人作为第一个模式参数,这意味着对象负责该事件的发生。第二个参数是 EventArgs的或子类(如 KeyEventArgs ),以提供更多的信息。虽然这是一个有点奇怪有 EventArgs的(其中包含pretty多没有信息)在一些事件处理程序委托类型,它意味着你可以注册一个通用事件处理程序,它可以处理的任何的事件符合格局。

Event handler delegate types in .NET in general (not specific to ASP.NET) follow a pattern of using Object sender as the first parameter, meaning the object responsible for the event occurring. The second parameter is either of EventArgs or a subclass (e.g. KeyEventArgs) to provide more information. Although it's a bit odd to have EventArgs (which contains pretty much no information) in some event handler delegate types, it does mean that you can register a "general purpose" event handler which can handle any event conforming to the pattern.

(WPF中的路由事件略有不同,IIRC,但你应该分别对这些读了。)

(Routed events in WPF are slightly different, IIRC, but you should read up on those separately.)

这篇关于什么是参数的目的,对象o和EventArgs的EA,在ddlChooseReport_Function(ASP.net)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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