ASP.NET Button 与 Linkbutton Enabled=“false” 行为
为什么具有 OnClientClick
属性并通过设置 Enabled="false"
禁用的 ASP.NET LinkButton
控件仍然呈现 onclick
HTML 中的事件处理程序,而 Button
控件则没有?
这似乎违反直觉。 由于在浏览器中无法真正禁用锚点,因此如果已在服务器端将其设置为禁用,则不附加 onclick 事件(和 href 属性)更有意义。
Why do ASP.NET LinkButton
controls with OnClientClick
attribute and disabled by setting Enabled="false"
still render onclick
event handler in HTML while Button
controls don't?
It seems counter-intuitive. Since anchors can't really be disabled in browsers, it makes more sense not to attach an onclick event (and href attribute) if it has been set disabled on server-side.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我同意它没有多大用处,但是如果不使用 ASP.NET 内置的众多方法之一更改链接按钮的呈现方式,您实际上对此无能为力。 除非您想有条件地处理客户端代码中的点击并检查元素属性。 这只是当前实现的方式,因此当您需要可以禁用的按钮功能时,最好完全远离链接按钮或锚点。
Well I would agree that it doesn't server much purpose, but without changing the way the linkbutton renders with one of the many methods built into asp.net there really isn't anything you can do about it. Unless you want to conditionally handle clicks in clientside code and check element attributes. This is just the way it is currently implemented so when you need the functionality of a button that can be disabled it is best to stay way from linkbuttons or anchors entirely.
这确实与asp.net 没有什么关系。
即使禁用后,超链接按钮仍会触发 onclick 事件。 底线:融入 HTML。 (输入标签在禁用时不会触发。)
This really has little to do with asp.net.
A hyperlink button still fires the onclick event even when disabled. Bottom line: baked into HTML. (An input tag, when disabled, does not fire.)