zoukankan      html  css  js  c++  java
  • 为ASP.NET按钮(Button)添加确认对话框

    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");
        }
    }
  • 相关阅读:
    《领域驱动设计的原则与实践》读书笔记(一)
    asp.net identity UserSecurityStamp 的作用
    Python Django Apache配置
    SQL语句优化(转载)
    【转】性能测试,影响 TPS 的一些因素
    【转】接口测试总结
    【转】两款 Web 前端性能测试工具
    【转】工作中使用Trepn Power Profiler的应用总结
    【转】nGrinder 简易使用教程
    Http协议状态码总结
  • 原文地址:https://www.cnblogs.com/Echo529/p/6386404.html
Copyright © 2011-2022 走看看