http://www.cnblogs.com/blodfox777/articles/1261303.html

Button有两个点击事件:

onclick 触发服务端事件,脚本为c#或VB.NET

OnClientClick 触发客户端事件,脚本一般为JavaScript,此属性为ASP.NET 2.0新增,1.1之前需要使用添加attribute的方法来添加客户端事件

在点击按钮时,先运行OnClientClick 中的脚本,如果返回值为true,则再运行button_onclick 中的代码, 否则将不会执行该按钮的后台代码

demo:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" 
            OnClientClick="return confirm('Are u sure?');" onclick="Button1_Click"/>
    </div>
    </form>
</body>
</html>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq; public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {     }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("if you press OK, Button1_Click will be execute");
    }
}

最新文章

  1. Redis在Linux下的安装和启动和配置
  2. 百度之星初赛2A 1001 ALL X(HDU 5690)
  3. wpf学习笔记
  4. .Net 自定义应用程序配置
  5. 找出进程中各线程cpu消耗情况
  6. mysql 动态sql语句
  7. nyist 604 小明的难题
  8. csuoj 1337: 搞笑版费马大定理
  9. (转)分布式搜索Elasticsearch——配置
  10. mongodb的地理位置索引
  11. JSP_DAO方式实现数据库查询(MyEclipse10,Tomcat7.0,JDK1.7,)——Java Web练习(四)
  12. 【开源java游戏框架libgdx专题】-09-动画的使用
  13. ADO.Net对Oracle数据库的操作【转载】
  14. linq中的临时变量
  15. mysql 批量修改表前缀
  16. 52e174ef38c96afbbeabe55d2ec53622 我知道这是什么
  17. HDU 5752 Sqrt Bo【枚举,大水题】
  18. wordpress安装五步法
  19. Exp5MSF基础应用——20164325王晓蕊
  20. turnserver 配置说明记录

热门文章

  1. html abbr标签 语法
  2. JUnit——Annotation
  3. Spring Cloud Stream教程(四)消费群体
  4. [LeetCode]-DataBase-Duplicate Emails
  5. python 调用c++类方法(1)
  6. p1848 [USACO12OPEN]书架Bookshelf
  7. Delphi XE2 之 FireMonkey 入门(38) - 控件基础: TPopupMenu、TMenuItem、TMenuBar、TMainMenu
  8. java8 查找字符串中首次出现2次的字母
  9. 九:flask-response响应
  10. IntToHex