AutoEventWireup 在具有许多控件的页面上为 false (C#)
使用 C#,有一个包含许多控件的 Web 表单,其中 AutoEventWireup 设置为 false。 这迫使您在构造函数中或通过重写 OnInit 来初始化所需的处理程序。
页面上的控件需要如何处理? 添加按钮 Click 和 SelectedIndexChanged 用于下拉列表和列表框,而不是添加到许多 GridView 事件等。
如果 AutoEventWireup 设置为 true,则会影响性能,因为所有控件(包括页面)的所有事件都将在场景,甚至是所有你不需要的场景。
当 AutoEventWireup 设置为 false 时,在 ctor/OnInit 中拥有一打或两个事件订阅是否合适? (this.Load+=...this.GridView1.Sorted+=...this.Button1.Click+=...等)
Using C#, there is a web form with many controls where the AutoEventWireup is set to false.
This forces you to initialize the handlers that you need in the ctor or by overriding OnInit.
What about the handling needed for the controls on the page?
Adding button Click's, and SelectedIndexChanged's for dropdowns and listboxes, not to many several GridView events, etc.
If AutoEventWireup was set to true, it would affect performance since all events for all controls (inc. the Page) would get wired-up behind the scenes, even all of those you didn't need.
With AutoEventWireup set to false, is it proper to have a dozen or two event subscriptions in the ctor/OnInit? (this.Load+=...this.GridView1.Sorted+=...this.Button1.Click+=...etc.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,如果您将
AutoEventWireup
设置为false
,您将需要自己手动连接所有事件。OnInit
方法是连接这些事件处理程序的好地方,并且您应该在其中拥有页面上控件所需的尽可能多的事件订阅。AutoEventWireup
是个好主意,但速度很慢,而且有点神奇。 我发现自己明确地进行接线要好得多。Yes, you will need to manually wire up all events yourself if you set
AutoEventWireup
tofalse
. TheOnInit
method is a good palce to wire these event handlers and you should have as many event subscriptions in there as you need for the controls on your page.AutoEventWireup
is a nice idea but is slow and is also a bit magical. I find it is much better to explicitly do the wireups yourself.AutoEventWireUp 仅自动连接某些内置页面或控件级事件,而不是页面上每个控件的每个事件。
有关列表,请参阅 Simon 对 “https://stackoverflow.com/questions/680878/what-does-autoeventwireup-page-property-mean/">这个问题。
AutoEventWireUp only automatically wires up certain built-in Page or control level events, not every event of every control on your Page.
For a list, see Simon's answer to this question.