不能这样用,应该在客户端事件上这样用:
btn.Attrbutes.Add("onclick","return confirm(\'are you sure?\')");--------------------------------
AspNetPager 免费分页控件4.0版发布,欢迎下载使用:http://www.webdiyer.com

解决方案 »

  1.   

    当然了,你客户端,服务器端混在一块了,
    Response.Write("<script>confirm('你确定要关闭本系统吗?')</script>");
    是客户端执行的,你服务器端输出这一句后当然是继续执行了,不可能起到你想要的作用的
    建议:1.要么完全用客户端来处理,然后根据用户选择结果来决定是否提交到服务器端执行
    2.写一公共类,放一个静态变量,同时,写一个要求用户是否关闭系统的页面,当用户确定关闭时,静态变量设为true,否则true;在当前页面获取该值进行判断
      

  2.   

    我有一个比较笨的方法,你可以定义一个Panel,当点击按钮时激活这个Panel,并获取用户在这个Panel中点击的按钮。然后根据获取的值,做操作
    例子:
    aspx文件内容
    <%@ Page language="c#" Codebehind="Win_CS_Repair.aspx.cs" AutoEventWireup="false" Inherits="catv.sjgb.Win_CS_Repair" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>Win_CS_Repair</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Win_CS_Repair" method="post" runat="server">
    <FONT face="宋体">
    <asp:Button id="Button_Open" style="Z-INDEX: 101; LEFT: 27px; POSITION: absolute; TOP: 18px" runat="server" Text="执行"></asp:Button>
    <asp:Panel id="Panel_Choice" style="Z-INDEX: 102; LEFT: 174px; POSITION: absolute; TOP: 171px" runat="server" Width="290px" Height="126px" BorderStyle="Outset" BorderWidth="2px" BackColor="ActiveBorder" HorizontalAlign="Center" Visible="False">
    <P>&nbsp;</P>
    <P>
    <asp:Label id="Label1" runat="server">你确定关闭本系统吗?</asp:Label></P>
    <P>
    <asp:Button id="Button_OK" runat="server" Text="确定"></asp:Button>&nbsp;
    <asp:Button id="Button_Cancel" runat="server" Text="取消"></asp:Button></P>
    </asp:Panel></FONT>
    </form>
    </body>
    </HTML>
    cs文件内容
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace catv.sjgb
    {
    /// <summary>
    /// Win_CS_Repair 的摘要说明。
    /// </summary>
    public class Win_CS_Repair : catv.Win_MyWeb
    {
    protected System.Web.UI.WebControls.Button Button_Open;
    protected System.Web.UI.WebControls.Panel Panel_Choice;
    protected System.Web.UI.WebControls.Label Label1;
    protected System.Web.UI.WebControls.Button Button_OK;
    protected System.Web.UI.WebControls.Button Button_Cancel;

    private void Page_Load(object sender, System.EventArgs e)
    {
    if(Session["Operatorid"] != null)
    {
    if(!this.IsPostBack)
    {
    this.SetWindowTitle("数据广播 - 信息卡报修记录 - 操作员:"+Session["OperatorName"]);
    }
    }
    else
    {
    this.WindowExit("联机超时,请重新登录!",0,1,"");
    }
    } #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Button_Open.Click += new System.EventHandler(this.Button_Open_Click);
    this.Button_OK.Click += new System.EventHandler(this.Button_OK_Click);
    this.Button_Cancel.Click += new System.EventHandler(this.Button_Cancel_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void Button_OK_Click(object sender, System.EventArgs e)
    {
    //此处放确认代码
    } private void Button_Cancel_Click(object sender, System.EventArgs e)
    {
    //此处放取消代码
    } private void Button_Open_Click(object sender, System.EventArgs e)
    {
    this.Panel_Choice.Visible = true;
    }
    }
    }
      

  3.   

    button1.Attributes["onClick"]="javascript:return confirm('确定解锁用户?');";
    这句话加到page_load()里面!