不能这样用,应该在客户端事件上这样用:
btn.Attrbutes.Add("onclick","return confirm(\'are you sure?\')");--------------------------------
AspNetPager 免费分页控件4.0版发布,欢迎下载使用:http://www.webdiyer.com
btn.Attrbutes.Add("onclick","return confirm(\'are you sure?\')");--------------------------------
AspNetPager 免费分页控件4.0版发布,欢迎下载使用:http://www.webdiyer.com
解决方案 »
- .cs页找不到对应.asp页的一个控件
- 如何把Excel表不同工作薄的数据导入Sql
- 怪事遇到汉字路径的问题
- ★求救,我得ASP.NET运行环境的问题??????奇怪中....
- 请教下大家,谢谢 了 !! 网站在IIS下运行正常, 在调试状态下运行报错. 发布后也运行正常
- 请问大家代码和页面分离与普通的有什么好处么?
- DataList 能不能实现下面这个效果?(欢迎大家进入)
- 请各位高手帮助: 这个数据库连接的程序片断,到底哪里有问题?
- 怎样用javascript来控制服务器控件的属性?
- SqlConnection strConn="server=localhost;uid=sa;pwd=;database=wux"; 总说Not associated with a trusted SQL Server connect,究竟如
- 看在菜鸟的分上,帮我一把了,求你了,thank
- 字符替换VB转C#的问题
Response.Write("<script>confirm('你确定要关闭本系统吗?')</script>");
是客户端执行的,你服务器端输出这一句后当然是继续执行了,不可能起到你想要的作用的
建议:1.要么完全用客户端来处理,然后根据用户选择结果来决定是否提交到服务器端执行
2.写一公共类,放一个静态变量,同时,写一个要求用户是否关闭系统的页面,当用户确定关闭时,静态变量设为true,否则true;在当前页面获取该值进行判断
例子:
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> </P>
<P>
<asp:Label id="Label1" runat="server">你确定关闭本系统吗?</asp:Label></P>
<P>
<asp:Button id="Button_OK" runat="server" Text="确定"></asp:Button>
<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;
}
}
}
这句话加到page_load()里面!