自动事件连线 [英] AutoEventwireup

查看:56
本文介绍了自动事件连线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

页面/主指令中AutoEventwireup的用途是什么?

What is the use of AutoEventwireup in page/master directive?

推荐答案

如果您在Google中进行搜索,则可以看到很多此类问题的解释.如果将此属性设置为true,则页面事件将自动与相应的事件处理程序关联.否则,您应该显式附加该事件.

autoeventwireup [
You can see lot of explanation for this type of questions if you search in Google. If you set this property to true then page events will automatically hooked up with corresponding event handlers. Otherwise you should explicitly attach the event.

autoeventwireup[^]


ASP.NET页面框架还支持一种自动方法来关联页面事件和方法.如果Page指令的AutoEventWireup属性设置为true(或者丢失,因为默认情况下为true),则页面框架将自动调用页面事件,尤其是Page_Init和Page_Load方法.在这种情况下,不需要显式的Handles子句或委托.
AutoEventWireup属性的缺点在于,它要求页面事件处理程序具有特定的,可预测的名称.这限制了您在命名事件处理程序时的灵活性.因此,在Visual Studio中,默认情况下AutoEventWireup属性设置为false,并且设计器生成显式代码以将页面事件绑定到方法.
如果将AutoEventWireup设置为true,则Visual Studio将生成代码以绑定事件,并且页面框架将根据事件的名称自动调用事件.这可能导致同一事件代码在页面运行时被调用两次.因此,在Visual Studio中工作时,应始终将AutoEventWireup设置为false.

谢谢
Hiren Solanki
the ASP.NET page framework also supports an automatic way to associate page events and methods. If the AutoEventWireup attribute of the Page directive is set to true (or if it is missing, since by default it is true), the page framework calls page events automatically, specifically the Page_Init and Page_Load methods. In that case, no explicit Handles clause or delegate is needed.
The disadvantage of the AutoEventWireup attribute is that it requires that the page event handlers have specific, predictable names. This limits your flexibility in how you name your event handlers. Therefore, in Visual Studio, the AutoEventWireup attribute is set to false by default and the designer generates explicit code to bind page events to methods.
If you do set AutoEventWireup to true, Visual Studio will generate code to bind the events and the page framework will automatically call events based on their names. This can result in the same event code being called twice when the page runs. As a consequence, you should always leave AutoEventWireup set to false when working in Visual Studio.

Thanks
Hiren Solanki


这篇关于自动事件连线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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