我有一个button
点击 button事件的时候  弹出一个对话框 提示你时候发送此信息
protected void Button1_Click(object sender, EventArgs e)
{
    if ((this.txtPackScore.Text.ToString().Trim().Length == 0))
        {
            //this.Label4.Visible = true;
            this.lblError.Text = "容量不能为空";
           
            return;
        }
        /
}在
pageload中
this.Button1.Attributes.Add("onclick", "return confirm('发送产品类型:'+document.getElementById('" + DropDownList1.ClientID + "').value+' 产品数量:'+document.getElementById('" + txtPackScore.ClientID + "').value)"); 每次点击按钮的时候 先弹出对话框  然后显示  this.lblError.Text = "容量不能为空";(如果txtPackScore为空的情况下)
我的目的是  先判断txtPackScore 是否为空 如果为空 就不弹出对话框  如果不为空就弹出对话框 “你是否发送此信息” 
怎么实现  谢谢各位来过的朋友 更谢谢留名的朋友

解决方案 »

  1.   

    刚有个朋友问的相似的问题
    直接上代码
    HTML<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="web_test.WebForm2" %><!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 type="text/javascript" language="javascript">
        function checkData()
        {
            if(form1.DropDownList1.value == "")
            {
                alert("选择内容不能为空");
                event.returnValue = false;
                return false;
            }
            
            var str = form1.DropDownList1.value;
            if(str != "")
            {
                if(confirm("你确实要做些操作选择吗?"))
                {
                    return true;
                }
                else
                {
                    event.returnValue = false;
                    return false;
                }
            }
        }
        
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            <asp:DropDownList ID="DropDownList1" runat="server" Width="80px">
                <asp:ListItem></asp:ListItem>
                <asp:ListItem>1</asp:ListItem>
                <asp:ListItem>2</asp:ListItem>
            </asp:DropDownList>
            <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
        
        </div>
        </form>
    </body>
    </html>c#using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;namespace web_test
    {
        public partial class WebForm2 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                this.Button1.Attributes.Add("onclick", "checkData()");
            }        protected void Button1_Click(object sender, EventArgs e)
            {
                //你要做的确定后的操作。            Response.Write("这是我确定后的操作!");
            }
        }
    }
      

  2.   

    将是否为空的判断放到JS里去做function check() {
      var aa = document.getElementById("<%=txtPackScore.ClientID%>").value;
      if (aa == "") {
        alert("容量不能为空");
        return false;
      }
      return confirm('.....');
    }
    this.Button1.Attributes.Add("onclick", "return check();");
      

  3.   

    1楼的代码需要修改function checkData()
        {
            var txtValue=document.getElementById('<%=txtPackScore.ClientID%>').value;
            var ddlValue=document.getElementById('<%=DropDownList1.ClientID%>').value;
            if( txtValue== "")
            {
                document.getElementById('<%=lblError.ClientID%>').innerText='容量不能为空';
                
                return false;
            }
            
                return confirm("发送产品类型:"+ddlValue+", 产品数量:"+txtValue));
                
        }
     ps: 要改的还真多~
      

  4.   


    this.Button1.Attributes.Add("onclick", "return checkData();");也可以设置 Button1的 OnClientClick属性 ="return checkData();"