ASP.Net的OnClick VS功能()处理buttonName.Click [英] ASP.Net OnClick vs Function() Handles buttonName.Click
问题描述
什么是使用一个ASP.Net按钮的onclick属性的区别是:
What is the difference between using the OnClick attribute of an ASP.Net Button:
< ASP:按钮的ID =BTN=服务器文本=新的OnClick =enterFunctionHere/>
VS。
直接在函数中使用的事件:
using the event directly in the function:
子ADDNEW()处理btn.Click
谢谢!
更新
如果我能在VB中都做,哪个更好?他们是平等的吗?
If I can do both in VB, which is better? Are they equal?
推荐答案
至少,在第一个选项,为.aspx页面生成的类是负责接线事件处理程序(因此,需要事件处理程序要 保护
);然而,在第二选项,codebehind类负责布线事件处理程序(因此在事件处理程序可以是 私人
)。
At the least, in the first option, the generated class for the .aspx page is responsible for wiring up the event handler (and thus, requires the event handler to be Protected
); whereas, in the second option, the codebehind class is responsible for wiring up the event handler (so the event handler can be Private
).
我不熟悉的把手
关键字在VB.NET实现的,但它也可能影响到线行动的时机到底如何(我知道,连接最多中的一个事件codebehind的 的OnInit
方法将在页面周期线了该方法在不同的时间比配置它通过标记,以及一些模糊的情况下,该事项)。
I'm not familiar with how exactly the Handles
keyword is implemented in VB.NET, but it may also affect the timing of the wire-up (I know that wiring up an event in a codebehind's OnInit
method will wire up the method at a different time in the page cycle than wiring it up through the markup, and a few obscure cases where that matters).
我个人而言,使用把手
方法(或使用 + =
在C#preFER 的OnInit
覆盖)。这允许编译器验证该方法存在并且没有不必要地暴露于继承的类。也正在编制时使用重构工具,查找用法等帮助。
I, personally, prefer using the Handles
method (or using +=
in C# in the OnInit
override). This allows the compiler to verify that the methods exist and don't have to be unnecessarily exposed to inheriting classes. Being compiled also helps when using refactoring tools, looking up usages, etc.
这篇关于ASP.Net的OnClick VS功能()处理buttonName.Click的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!