zoukankan      html  css  js  c++  java
  • JS代码Confirm确认和取消判断执行不同的事件

    Default.aspx页面:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <!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>Are you Ready?</title>
    </head>
    <body>
        <form id="form1" runat="server">  
            <asp:HiddenField ID="HiddenField1" runat="server" />
            <asp:button id="Button1" runat="server" Text="Are you ready?" OnClick="Button1_Click"></asp:button>  
        </form>
    </body>
    </html>
    Default.cs页面
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Text;

    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            StringBuilder strbConfirmScript = new StringBuilder();

            strbConfirmScript.Append("<script language='javascript' type='text/javascript'>\n");

            strbConfirmScript.Append("function showConfirm()\n");
            strbConfirmScript.Append("{\n  var returnValue=confirm('Are you Sure?');\n");
            strbConfirmScript.Append("  if(returnValue!=undefined) \n document.getElementById('HiddenField1').value=returnValue; \n");
            strbConfirmScript.Append("}\n");
            strbConfirmScript.Append("</script>\n");

            ClientScript.RegisterClientScriptBlock(this.GetType(), "AreYouConfirm", strbConfirmScript.ToString());

            Button1.Attributes.Add("onclick", "showConfirm()");
        }
        protected void Button1_Click(object sender, System.EventArgs e)
        {
            if (HiddenField1.Value == "true")
                ClientScript.RegisterStartupScript(this.GetType(), "script", "alert('A');", true);
            else
                ClientScript.RegisterStartupScript(this.GetType(), "script", "alert('B');", true);

        }
    }

  • 相关阅读:
    XidianOJ 1073 Nunchakus
    XidianOJ 1024 2的幂次表示
    XidianOJ 1072 National Disaster
    XidianOJ 1093 一元三次方程
    中国剩余定理
    bzoj2818(欧拉函数递推)
    poj2311(博弈论,sg函数)
    contesthunter#46-A(分块)
    Tree,点分治
    poj3580(splay 毒瘤题)
  • 原文地址:https://www.cnblogs.com/zhangpengshou/p/957411.html
Copyright © 2011-2022 走看看