服务端给button添加了onclick导致CustomValidator的alert失效
服务端给提交按钮增加onclick属性,结果CustomValidator的alert属性不提示了
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
tj.OnClientClick = "return confirm('确定提交数据吗?');";
//tj.Attributes.Add("onclick", "return confirm('确定提交数据吗?');");
BaseAccess qxSql = new BaseAccess();
qxSql.CommandText = "select * from zsxx where sid=0";
DataSet ds = qxSql.ExecuteDataset();
szxx.DataSource = ds;
szxx.DataTextField = ds.Tables[0].Columns[2].ColumnName;
szxx.DataValueField = ds.Tables[0].Columns[1].ColumnName;
szxx.DataBind();
}
}
CustomValidator调用函数
<script type="text/javascript">
function myVal() {
var xm = document.getElementById("xm").value;
var zkzh = document.getElementById("zkzh").value;
var cj = document.getElementById("zf").value;
var lxdh = document.getElementById("lxdh1").value;
if (xm.length < 1 || zkzh.length<11 || cj.length<3 || lxdh<11) {
alert("部分必填项未填写或联系电话、准考证位数有误!");
return;
}