我要在“保存”的按钮click事件里面实现如下功能,
先根据用户输入的数据到数据库进行判断,满足条件A的直接提示不能添加记录。
满足条件B的询问用户是否确认添加,确认继续,取消返回。
两个都不满足的,直接执行下去。问题就是如果用addBtn.Attributes.Add("onclick", "javascript:...这种方式,是不管什么条件都进行询问的,我要的是先判断了用户的数据后再进行提问。
我以前都是做C/S的,对web开发不熟悉,网上查了一些东西都是说用javascript+div来实现对话框效果,但是还是没有好的结果。
麻烦用过的或者有例子的告诉我该如何弄,多谢了,分数全部送上哦。
先根据用户输入的数据到数据库进行判断,满足条件A的直接提示不能添加记录。
满足条件B的询问用户是否确认添加,确认继续,取消返回。
两个都不满足的,直接执行下去。问题就是如果用addBtn.Attributes.Add("onclick", "javascript:...这种方式,是不管什么条件都进行询问的,我要的是先判断了用户的数据后再进行提问。
我以前都是做C/S的,对web开发不熟悉,网上查了一些东西都是说用javascript+div来实现对话框效果,但是还是没有好的结果。
麻烦用过的或者有例子的告诉我该如何弄,多谢了,分数全部送上哦。
protected void btnAdd_Click()
{
//string aa=this.txtname.text;//得到用户名
这里调用方法查看数据库是否有 条件A
如果有的话 弹出对话框 alert ('不能添加记录')
if条件B
alert('是否确认添加')
}
知道了这个东西支持部分刷新,而不是整个页面刷新,但是对于我想要实现的目的,该怎么去关联起来?
你的js的confirm中,如果返回true,则让hidden为1
2。在page_load里
if(this.hidden1.value == "1")
{
MyQuery()
}
private void MyQuery()
{
//这个就是从数据库进行判断的方法
}
没看明白,后台代码里面可以直接Alert吗,你如何得到返回值?
后台服务端代码和JS 放在一起使用感觉太让人头疼...我也希望能了解一个好的方法...
MyQuery方法 在add_click里时,一定要放在最后
==============
网上搜了个,<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>弹出提示</title>
<style>
* {margin:0;padding:0;font-size:12px;}
html,body {height:100%;width:100%;}
#content {background:#f8f8f8;padding:30px;height:100%;}
#content a {font-size:30px;color:#369;font-weight:700;}
#alert {border:1px solid #369;width:300px;height:150px;background:#e2ecf5;z-index:1000;position:absolute;display:none;}
#alert h4 {height:20px;background:#369;color:#fff;padding:5px 0 0 5px;}
#alert h4 span {float:left;}
#alert h4 span#close {margin-left:210px;font-weight:500;cursor:pointer;}
#alert p {padding:12px 0 0 30px;}
#alert p input {width:120px;margin-left:20px;}
#alert p input.myinp {border:1px solid #ccc;height:16px;}
#alert p input.sub {width:60px;margin-left:30px;}
</style>
</head>
<body>
<div id="content">
<a href="#">注册</a>
</div>
<div id="alert">
<h4><span>现在注册</span><span id="close">关闭</span></h4>
<p><label>用户名</label><input type="text" class="myinp" onmouseover="this.style.border='1px solid #f60'" onfoucs="this.style.border='1px solid #f60'" onblur="this.style.border='1px solid #ccc'" /></p>
<p><label>密 码</label><input type="password" class="myinp" onmouseover="this.style.border='1px solid #f60'" onfoucs="this.style.border='1px solid #f60'" onblur="this.style.border='1px solid #ccc'" /></p>
<p><input type="submit" value="注册" class="sub" /><input type="reset" value="重置" class="sub" /></p>
</div>
<script type="text/javascript">
var myAlert = document.getElementById("alert");
var reg = document.getElementById("content").getElementsByTagName("a")[0];
var mClose = document.getElementById("close");
reg.onclick = function()
{
myAlert.style.display = "block";
myAlert.style.position = "absolute";
myAlert.style.top = "50%";
myAlert.style.left = "50%";
myAlert.style.marginTop = "-75px";
myAlert.style.marginLeft = "-150px";
mybg = document.createElement("div");
mybg.setAttribute("id","mybg");
mybg.style.background = "#000";
mybg.style.width = "100%";
mybg.style.height = "100%";
mybg.style.position = "absolute";
mybg.style.top = "0";
mybg.style.left = "0";
mybg.style.zIndex = "500";
mybg.style.opacity = "0.3";
mybg.style.filter = "Alpha(opacity=30)";
document.body.appendChild(mybg);
document.body.style.overflow = "hidden";
}
mClose.onclick = function()
{
myAlert.style.display = "none";
mybg.style.display = "none";
}
</script>
</body>
</html>
{
if(符合条件A)
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('无法添加')</script>"); }
if(符合条件B)
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>if(confirm('确认继续?')){window.location.href='Default.aspx'}</script>");
}
}这样应该很明白了把
楼主是要先去数据库查询是否满足条件,然后再弹出对话框...
你的是先判断confirm对话框返回是true还是false,再到数据库进行操作...
{
onSuccess:function(transport)
{
var result=transport.responseText;
if(result=="0"){满足条件A的操作;}
if(result!="0"){
var b=confirm("确认");
if(b)
//条件B的确认操作
}
}
});
这里你针对接收的数据做处理,然后 response.write 结果就可以了
http://blog.csdn.net/Sandy945/archive/2010/07/06/5715583.aspx
luli668,sywcf 你们好,非常感谢谢谢你们的帮助,你们要一直进行关注奥。我一会去吃饭,下午会努力解决这个问题,下午我会弄一个简单的例子,然后按照sywcf 的说法试一下,不过看你最开始的回复
。。
。。
1。你在页面中放一个hidden,可以默认为0
你的js的confirm中,如果返回true,则让hidden为1
2。在page_load里
if(this.hidden1.value == "1")
{
MyQuery()
}
其中里面的这句话“你的js的confirm中,如果返回true,则让hidden为1”
这个confirm是提示什么呢,因为这个时候还没进行判断?
1.前面有人说过了,使用隐藏控件.根据第一次点击时后台cs代码返回的值.去执行"点击隐藏控件",这个很容易搜到.
2.前面也有人说过了.使用ajax.加上onclientclick="查询();"代码,先执行"查询()"函数.通过ajax查询.得到结果并提示或者直接进行下一步操作等.都有人说过了.自己总慢人一步啊
前台:
<!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>");
}
}
}
如果是这样的话,肯定行的...老兄前面的回复
1。你在页面中放一个hidden,可以默认为0
你的js的confirm中,如果返回true,则让hidden为1
2。在page_load里
if(this.hidden1.value == "1")
{
MyQuery()
}
private void MyQuery()
{
//这个就是从数据库进行判断的方法
}这样绝对会让人理解错..
学习了...我想问问,这句 this.ClientScript.RegisterStartupScript(this.GetType(), "ss", "<script>MyConfirm();</script>");改成
his.ClientScript.RegisterStartupScript(this.GetType(), "ss", "<script>return confirm('是否确认继续?');</script>"); 这样,不用MyConfirm,这种会不会成功,现在电脑上没vs。。
恩,我看了,理解你的意思...confirm成功将隐藏值置为1,然后submit提交,然后pageload时,如果隐藏值是1就继续执行下去...
我只是在想这个过程能不能再简单一点...
我已经把代码贴过来,把C#的转换成vb了,是没有问题的。一会分数送上啊,
就是一个小小的地方,可能是需要想另外的办法了,就是弹出的是否继续的窗口的标题不能够换,能换吗?
Microsoft INternet Explor?
“确定要继续吗?”
我说的标题就是小窗口的标题,我这边是英文操作系统显示的是“Message from WebPage”,中文的不知道显示什么。这个标题估计是不好换的,我以前曾经尝试过的,问问你们看看呢
Response.Write("<script>alert('不能添加!')
Response.End();
}else if(B){
Response.Write("<script>confirm('确认是否添加?')
//添加操作 Response.End();
}else{
XXXXXXXXXX
}