我想在页面保存的时候出现一个对话框,其中有一项要提示信息 是否继续操作这是我的源码,我点确定或取消,它都会保存。。求大虾解答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>");
                                    }
                                }

解决方案 »

  1.   

    保存按钮里 onclientclick="return confirm()" onclick="保存的事件"
      

  2.   

    <script>confirm('底盘VIN输入有误,正确为底盘VIN17位还需要继续吗?'); </script>"); 这段JS应该加在你执行操作的控件的onclientclick里
      

  3.   

    这个里面
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {}
      

  4.   

    在HTML视图里加上一个onclientclick属性试试<ImageButton id="ImageButton1" onclientclick="<script>confirm('底盘VIN输入有误,正确为底盘VIN17位还需要继续吗?'); </script>" />C#代码中删掉
    Page.RegisterStartupScript(" <script>confirm('底盘VIN输入有误,正确为底盘VIN17位还需要继续吗?'); </script>"); 
      

  5.   

    你的程序结构设计不对。给你写个demo自己研究一下运行机制:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!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>
    </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);
            }
        }
    }
      

  6.   


    funcation test(len)
    {
      if(len==17)
    {
      return confirm('底盘VIN输入有误,正确为底盘VIN17位还需要继续吗?');
    }
    }<asp:ImageButton id="ImageButton1" runat="server" onClientClick="test(len)" />
      

  7.   

    要注意,你不得不把后台程序分成两个阶段,第一个阶段输出脚本来执行confirm,之后(当选择确认之后)页面重新调用自己的功能(而不调用任何控件),所以这需要使用IPostBackEventHandler接口来为页面对象提供可以回发并处理命名参数的机制。
      

  8.   

    this.Page.GetPostBackEventReference(this, "len等于17")
    这个函数会输出一个javascript脚本,它回调页面本身(this),并且传回的命令参数(类似于GridView等的CommandName)是“len等于17”。然后使用string.Formmat函数把它放入scp字符串中的{0}部分。然后RegisterStartupScript输出脚本,这一步你是做对了的!你可以看看浏览器上的html源代码,看看输出的脚本命令是什么。
    这里的关键是要把后台操作中间插入客户端动作,所以使用了IPostBackEventHandler接口功能为页面插入回调处理第二阶段工作的功能。
      

  9.   

     protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            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位还需要继续吗?”如果确定就保存,取消则不保存。
    以上的代码是无论确定与否都会保存,请教一下应该怎么改才符合要求,谢谢!!!(最好帮忙写下代码)