在ASP.net中关于Attributes.Add()

辰爸 2009-12-22 04:24:55
btnDoc.Attributes.Add("onclick","AddFA();return false;");
跟这个<asp:button id="btnSearch" runat="server" CssClass="redbtn" Text="查询" onclick="btnSearch_Click">
的onclick有什么区别?如果同时存在的话,会先执行哪一个?(对于同一个按钮来说)
...全文
424 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
wyp19870608 2011-08-30
  • 打赏
  • 举报
回复
学习了
辰爸 2009-12-22
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 youbl 的回复:]
btnDoc.Attributes.Add("onclick","AddFA();return false;");
跟这个 <asp:button id="btnSearch" runat="server" CssClass="redbtn" Text="查询" onclick="btnSearch_Click">

这2个都写,等同于:
<asp:button id="btnSearch" runat="server" CssClass="redbtn" Text="查询" onclick="btnSearch_Click" onclientclick="AddFA();return false;">

下面这个效果也相同:
<input type="button" id="btnSearch" runat="server" value="查询" onserverclick="btnSearch_Click" onclick="AddFA();return false;">
[/Quote]
谢谢,学习了!
hitlcyu19 2009-12-22
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 lovely_baby 的回复:]
引用 12 楼 wsj1983920 的回复:
引用 7 楼 lovely_baby 的回复:
个人感觉没区别~~
有先后顺序

那就肯定有顺序~~
呵呵
[/Quote]
汗。。前面的是客户端的
yuquanzuo 2009-12-22
  • 打赏
  • 举报
回复
当然先执行前面个
而且你返回false就不会执行后面那个了!
Lovely_baby 2009-12-22
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 wsj1983920 的回复:]
引用 7 楼 lovely_baby 的回复:
个人感觉没区别~~
有先后顺序
[/Quote]
那就肯定有顺序~~
呵呵
wsj1983920 2009-12-22
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 lovely_baby 的回复:]
个人感觉没区别~~
[/Quote]有先后顺序
cuike519 2009-12-22
  • 打赏
  • 举报
回复
显然是前者先执行即客户端的先执行,之后页面会submit然后才是服务器按钮事件的执行。
游北亮 2009-12-22
  • 打赏
  • 举报
回复
btnDoc.Attributes.Add("onclick","AddFA();return false;");
跟这个 <asp:button id="btnSearch" runat="server" CssClass="redbtn" Text="查询" onclick="btnSearch_Click">

这2个都写,等同于:
<asp:button id="btnSearch" runat="server" CssClass="redbtn" Text="查询" onclick="btnSearch_Click" onclientclick="AddFA();return false;">

下面这个效果也相同:
<input type="button" id="btnSearch" runat="server" value="查询" onserverclick="btnSearch_Click" onclick="AddFA();return false;">
bj_kevin51 2009-12-22
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 youbl 的回复:]
前者是添加js事件,后者是添加服务器端响应事件
2者不是一个概念,如果都写

先执行果事件,再执行服务器端响应事件

不过你这里,因为return false;了,所以服务器端响应事件永远执行不了(因为不会提交)
[/Quote]

挺在理 学习了。
igelf 2009-12-22
  • 打赏
  • 举报
回复
先执行客户端事件~
Lovely_baby 2009-12-22
  • 打赏
  • 举报
回复
个人感觉没区别~~
bj_kevin51 2009-12-22
  • 打赏
  • 举报
回复
没有专门试过,不过这俩种方法用的狠平凡,当然得看程序需求而定。
只要能不走服务器代码我就尽量不走。
游北亮 2009-12-22
  • 打赏
  • 举报
回复
前者是添加js事件,后者是添加服务器端响应事件
2者不是一个概念,如果都写

先执行果事件,再执行服务器端响应事件

不过你这里,因为return false;了,所以服务器端响应事件永远执行不了(因为不会提交)
wsj1983920 2009-12-22
  • 打赏
  • 举报
回复
btnDoc.Attributes.Add("onclick","AddFA();return false;"); 先执行这个
因为是客户端事件
xiaowen_ly 2009-12-22
  • 打赏
  • 举报
回复
调试吧兄弟
wyfde123 2009-12-22
  • 打赏
  • 举报
回复
你调试下就知道了~~
xupeihuagudulei1 2009-12-22
  • 打赏
  • 举报
回复
前一种是在客户端执行的

不会刷新页面。
后一种与服务器交替了一回。
当然先执行客户端的那个attributes.add()
Over 50 engaging recipes for learning advanced concepts of .NET Framework 4.5 Overview Explores the advanced features of core .Net concepts in step-by-step detail. Understand great ways to enhance your website by securing against cross-site scripting attacks, enabling third party authentications, and embedding maps. Covers interesting real world projects with ASP.net, Silverlight, ADO.net, and Entity Framework. In Detail .Net is an architecture neutral and programming language agnostic framework that caters to all requirements, varying from business solutions to multiplayer online 3D games. Version 4.5 added many new features to help with the development of robust and user-friendly solutions. This book will teach you the new features as well as the advanced concepts of different .Net components. ".Net Framework 4.5 Expert Programming Cookbook" will teach you about the advanced concepts and new features of the core framework, Window Forms, threading, and parallel programming, ASP.Net, Silverlight, WCF, WPF, ADO.Net, and Entity Framework using a real life problem/solution approach with a hands-on style. This book takes a hands-on approach in teaching you how to use the new as well as advanced features of the .Net framework 4.5. Each topic will teach you how to use a specific feature of .Net to solve a real world problem or scenario. You will learn how to use metadata driven programming, creating custom events with payloads, adding parallel constructs to your applications, using strict data bound controls in ASP.Net, enabling third party authentication and embedding maps, among many other key skills. What you will learn from this book Create metadata-driven code, including properties, events, and custom attributes . Understand multi-threading, thread-safety, and the parallel framework extensions to avoid threading pitfalls in your Window Forms, WPF, and Silverlight applications. Implement .NET patterns in application design, assessing a given pattern’s fit in a

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧