我想在页面保存的时候出现一个对话框,其中有一项要提示信息 是否继续操作这是我的源码,我点确定或取消,它都会保存。。求大虾解答if (len == 17)
{
Page.RegisterStartupScript("<script>confirm('底盘VIN输入有误,正确为底盘VIN17位还需要继续吗?');</script>");
//下面是数据绑定,执行操作
string t1 = this.TextBox1.Text.Trim();
string t2 = this.TextBox3.Text.Trim();
string t3 = this.TextBox4.Text.Trim();
string t4 = this.TextBox17.Text.Trim();
string t5 = this.TextBox18.Text.Trim();
string t6 = this.TextBox19.Text.Trim();
string t7 = this.TextBox20.Text.Trim();
string t8 = this.TextBox21.Text.Trim();
string t9 = this.TextBox22.Text.Trim();
string t10 = this.TextBox23.Text.Trim();
string t11 = this.TextBox24.Text.Trim();
string t12 = this.TextBox25.Text.Trim();
string t13 = this.TextBox26.Text.Trim();
strsql = "insert into autoinfo_Guest values('" + this.chengshi.SelectedValue + "','" + t1 + "','" + t2 + "','" + t3 + "','" + t4 + "','" + t5 + "','" + t6 + "','" + t7 + "','" + t8 + "','" + t9 + "','" + t10 + "','" + t11 + "','" + t12 + "','" + t13 + "')";
bool zz = Das.ExecSql(strsql);
strsql = "insert into autoinfo_company (车牌号,网点编号) values('" + str + "','" + this.Session["id"].ToString() + "')";
zz = Das.ExecSql(strsql);
strsql = "select 客户代码 from autoinfo_Guest order by 客户代码 desc";
dv = Das.CreateDataView(strsql);
string guestid = Convert.ToString(dv.Table.Rows[0][0]).Trim();
string pinpaiid = this.DropDownList2.SelectedValue.Trim();
string guigeid = this.DropDownList3.SelectedValue.Trim();
string color = this.DropDownList4.SelectedValue.Trim();
string shangpairiqi = this.TextBox5.Text.Trim();
string yongtu = this.DropDownList1.Text.Trim();
string fadongji = this.TextBox8.Text.Trim();
string dipan = this.TextBox9.Text.Trim();
string bsx = this.TextBox10.Text.Trim();
string memo = this.TextBox11.Text.Trim();
string carno = str;
string nians = this.TextBox13.Text.Trim();
string jiazhao = this.TextBox14.Text.Trim();
string baoxian = this.TextBox15.Text.Trim();
if (this.TextBox9.Text != "")
{
strsql = "select 车牌号 from autoinfo where 底盘VIN = '" + this.TextBox9.Text + "'";
dv = Das.CreateDataView(strsql);
if (dv.Table.Rows.Count > 0)
{
string error = "insert into autoinfo_question (底盘号码,操作类型,错误说明) values ('" + this.TextBox9.Text + "','底盘重复','该车辆的车架号数据库存在重复,请查询修改')";
bool zzz = Das.ExecSql(error);
}
} string t17 = string.Format("{0:yyyy-MM-dd}", DateTime.Now); strsql = "insert into autoinfo (车牌号,客户代码,品牌序号,车型序号,车辆颜色,上牌日期,车辆用途,车辆来源,发动机号,底盘VIN,变速箱号,车辆年审,驾照年审,保险到期,新增日期,维修日期,客服员,状态,备注,网点编号,厂商序号) values('" + carno + "','" + guestid + "','" + pinpaiid + "','" + guigeid + "','" + color + "','" + shangpairiqi + "','" + yongtu + "','" + this.rb_laiyuan.Text + "','" + fadongji + "','" + dipan + "','" + bsx + "','" + nians + "','" + jiazhao + "','" + baoxian + "','" + t17 + "','" + t17 + "','','空闲','" + memo + "','" + this.Session["id"].ToString() + "'," + this.DropDownList5.SelectedValue + ")"; bool z = Das.ExecSql(strsql);
int i;
for (i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (this.CheckBoxList1.Items[i].Selected == true)
{
strsql = "insert into autoinfo_interest (车牌号,兴趣序号) values('" + carno + "','" + this.CheckBoxList1.Items[i].Value + "')";
z = Das.ExecSql(strsql);
}
} int j;
for (j = 0; j < CheckBoxList2.Items.Count; j++)
{
if (this.CheckBoxList2.Items[j].Selected == true)
{
strsql = "insert into autoinfo_drink (车牌号,饮品序号) values('" + carno + "','" + this.CheckBoxList2.Items[j].Value + "')";
z = Das.ExecSql(strsql);
}
} if (z)
{
Response.Write("<script language='javascript'>window.opener.location.href=window.opener.location.href;window.close();</script>");
}
else
{
Page.RegisterStartupScript("警告", "<script>alert('车辆信息添加失败!');</script>");
}
}
{
Page.RegisterStartupScript("<script>confirm('底盘VIN输入有误,正确为底盘VIN17位还需要继续吗?');</script>");
//下面是数据绑定,执行操作
string t1 = this.TextBox1.Text.Trim();
string t2 = this.TextBox3.Text.Trim();
string t3 = this.TextBox4.Text.Trim();
string t4 = this.TextBox17.Text.Trim();
string t5 = this.TextBox18.Text.Trim();
string t6 = this.TextBox19.Text.Trim();
string t7 = this.TextBox20.Text.Trim();
string t8 = this.TextBox21.Text.Trim();
string t9 = this.TextBox22.Text.Trim();
string t10 = this.TextBox23.Text.Trim();
string t11 = this.TextBox24.Text.Trim();
string t12 = this.TextBox25.Text.Trim();
string t13 = this.TextBox26.Text.Trim();
strsql = "insert into autoinfo_Guest values('" + this.chengshi.SelectedValue + "','" + t1 + "','" + t2 + "','" + t3 + "','" + t4 + "','" + t5 + "','" + t6 + "','" + t7 + "','" + t8 + "','" + t9 + "','" + t10 + "','" + t11 + "','" + t12 + "','" + t13 + "')";
bool zz = Das.ExecSql(strsql);
strsql = "insert into autoinfo_company (车牌号,网点编号) values('" + str + "','" + this.Session["id"].ToString() + "')";
zz = Das.ExecSql(strsql);
strsql = "select 客户代码 from autoinfo_Guest order by 客户代码 desc";
dv = Das.CreateDataView(strsql);
string guestid = Convert.ToString(dv.Table.Rows[0][0]).Trim();
string pinpaiid = this.DropDownList2.SelectedValue.Trim();
string guigeid = this.DropDownList3.SelectedValue.Trim();
string color = this.DropDownList4.SelectedValue.Trim();
string shangpairiqi = this.TextBox5.Text.Trim();
string yongtu = this.DropDownList1.Text.Trim();
string fadongji = this.TextBox8.Text.Trim();
string dipan = this.TextBox9.Text.Trim();
string bsx = this.TextBox10.Text.Trim();
string memo = this.TextBox11.Text.Trim();
string carno = str;
string nians = this.TextBox13.Text.Trim();
string jiazhao = this.TextBox14.Text.Trim();
string baoxian = this.TextBox15.Text.Trim();
if (this.TextBox9.Text != "")
{
strsql = "select 车牌号 from autoinfo where 底盘VIN = '" + this.TextBox9.Text + "'";
dv = Das.CreateDataView(strsql);
if (dv.Table.Rows.Count > 0)
{
string error = "insert into autoinfo_question (底盘号码,操作类型,错误说明) values ('" + this.TextBox9.Text + "','底盘重复','该车辆的车架号数据库存在重复,请查询修改')";
bool zzz = Das.ExecSql(error);
}
} string t17 = string.Format("{0:yyyy-MM-dd}", DateTime.Now); strsql = "insert into autoinfo (车牌号,客户代码,品牌序号,车型序号,车辆颜色,上牌日期,车辆用途,车辆来源,发动机号,底盘VIN,变速箱号,车辆年审,驾照年审,保险到期,新增日期,维修日期,客服员,状态,备注,网点编号,厂商序号) values('" + carno + "','" + guestid + "','" + pinpaiid + "','" + guigeid + "','" + color + "','" + shangpairiqi + "','" + yongtu + "','" + this.rb_laiyuan.Text + "','" + fadongji + "','" + dipan + "','" + bsx + "','" + nians + "','" + jiazhao + "','" + baoxian + "','" + t17 + "','" + t17 + "','','空闲','" + memo + "','" + this.Session["id"].ToString() + "'," + this.DropDownList5.SelectedValue + ")"; bool z = Das.ExecSql(strsql);
int i;
for (i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (this.CheckBoxList1.Items[i].Selected == true)
{
strsql = "insert into autoinfo_interest (车牌号,兴趣序号) values('" + carno + "','" + this.CheckBoxList1.Items[i].Value + "')";
z = Das.ExecSql(strsql);
}
} int j;
for (j = 0; j < CheckBoxList2.Items.Count; j++)
{
if (this.CheckBoxList2.Items[j].Selected == true)
{
strsql = "insert into autoinfo_drink (车牌号,饮品序号) values('" + carno + "','" + this.CheckBoxList2.Items[j].Value + "')";
z = Das.ExecSql(strsql);
}
} if (z)
{
Response.Write("<script language='javascript'>window.opener.location.href=window.opener.location.href;window.close();</script>");
}
else
{
Page.RegisterStartupScript("警告", "<script>alert('车辆信息添加失败!');</script>");
}
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{}
Page.RegisterStartupScript(" <script>confirm('底盘VIN输入有误,正确为底盘VIN17位还需要继续吗?'); </script>");
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<br />
<asp:Label ID="Label1" runat="server" Text="还没有处理计算部分"></asp:Label>
</form>
</body>
</html>
using System;
using System.Web.UI;public partial class Default2 : System.Web.UI.Page, IPostBackEventHandler
{
#region IPostBackEventHandler Members public void RaisePostBackEvent(string eventArgument)
{
switch (eventArgument)
{
case "len等于17":
this.Label1.Text = "已经处理完成计算部分";
this.TextBox1.Enabled = false;
return;
case "另一个功能的标题":
return;
}
} #endregion
protected void Button1_Click(object sender, EventArgs e)
{
if (int.Parse(this.TextBox1.Text) == 17) //注意只是demo,所以没有做异常处理
{
var scp = "if(confirm('底盘VIN输入有误,正确为底盘VIN17位还需要继续吗?')){0};";
this.Page.ClientScript.RegisterStartupScript(this.GetType(), this.GetHashCode().ToString(),
string.Format(scp, this.Page.GetPostBackEventReference(this, "len等于17")), true);
}
}
}
funcation test(len)
{
if(len==17)
{
return confirm('底盘VIN输入有误,正确为底盘VIN17位还需要继续吗?');
}
}<asp:ImageButton id="ImageButton1" runat="server" onClientClick="test(len)" />
这个函数会输出一个javascript脚本,它回调页面本身(this),并且传回的命令参数(类似于GridView等的CommandName)是“len等于17”。然后使用string.Formmat函数把它放入scp字符串中的{0}部分。然后RegisterStartupScript输出脚本,这一步你是做对了的!你可以看看浏览器上的html源代码,看看输出的脚本命令是什么。
这里的关键是要把后台操作中间插入客户端动作,所以使用了IPostBackEventHandler接口功能为页面插入回调处理第二阶段工作的功能。
{
byte[] mybyte = System.Text.Encoding.Default.GetBytes(this.TextBox9.Text);
int len = mybyte.Length;
if (len != 17)
{
Response.Write("<script>confirm('底盘VIN输入有误,正确为底盘VIN17位还需要继续吗?');</script>");
bind();//这里是保存数据到数据库
}
else
{
bind();//这里是保存数据到数据库
}
、
}
我要的是TextBox9中的字符长度如果等于17直接保存,不等于时提示“底盘VIN输入有误,正确为底盘VIN17位还需要继续吗?”如果确定就保存,取消则不保存。
以上的代码是无论确定与否都会保存,请教一下应该怎么改才符合要求,谢谢!!!(最好帮忙写下代码)