请问大家:
我现在有一个页面要实现如下功能。
在一个IF语句中弹出带确定和取消提示框:比如
protected void Button1_Click(object sender, EventArgs e)
{
if (this.TextBox1.Text == "")
{
SqlConnection myButton1Cn = new SqlConnection(strConn);
myButton1Cn.Open();
myButton1Cn.Close();
}
}
符合这个条件就弹出一个提示框,并且,在点击确定后才执行下面的语句,点击取消的就不进行任何操作。不要说在Button1的OnClientClick里写confirm("确定吗?")那样在TextBox1不为空的情况下也会弹出提示框。
要实现的效果类似下面网站的功能:
http://biz.shm.com.cn/zw/ask.aspx
我现在有一个页面要实现如下功能。
在一个IF语句中弹出带确定和取消提示框:比如
protected void Button1_Click(object sender, EventArgs e)
{
if (this.TextBox1.Text == "")
{
SqlConnection myButton1Cn = new SqlConnection(strConn);
myButton1Cn.Open();
myButton1Cn.Close();
}
}
符合这个条件就弹出一个提示框,并且,在点击确定后才执行下面的语句,点击取消的就不进行任何操作。不要说在Button1的OnClientClick里写confirm("确定吗?")那样在TextBox1不为空的情况下也会弹出提示框。
要实现的效果类似下面网站的功能:
http://biz.shm.com.cn/zw/ask.aspx
前台:
<!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></title>
<script>
function MyConfirm() {
if (confirm("确定要继续吗?") == true) {
document.getElementById("hidden1").value = "1";
}
else {
document.getElementById("hidden1").value = "0";
}
form1.submit();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="hidden" id="hidden1" runat="server" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="测试Confirm"
onclick="Button1_Click" />
</form>
</body>
</html>后台:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;namespace ConfirmTest
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (this.hidden1.Value == "1")
{
this.MyGo();
}
} protected void Button1_Click(object sender, EventArgs e)
{
//从数据库中取数据进行判断
//这里简单的改为判断页面上的textbox
if (this.TextBox1.Text == "1")
{
this.ClientScript.RegisterStartupScript(this.GetType(),"ss","<script>alert('不能添加!');</script>");
return;
}
else if (this.TextBox1.Text == "2")
{
this.ClientScript.RegisterStartupScript(this.GetType(), "ss", "<script>MyConfirm();</script>");
}
else
{
MyGo();
}
} //需要继续执行的方法
private void MyGo()
{
this.ClientScript.RegisterStartupScript(this.GetType(), "ss", "<script>alert('是不是想要这个效果呢?');</script>");
}
}
}