给dropdownlist等控件增加客户端onchange事件
dropdownlist等控件的onchange事件,如果同时要触发js弹出框,则采用以下方法:
后台:
if (iStatusNo == (int)ZTE.EVAL.Model.EnumCollections.InvestigateStatus.已发布)
{
this.ddlOperation.Items.Add(new ListItem(OperType.预览.ToString(),pkValue));
this.ddlOperation.Items.Add(new ListItem(OperType.关闭.ToString(),pkValue));
this.ddlOperation.Items.Add(new ListItem(OperType.全部跟催.ToString(),pkValue));
this.ddlOperation.Items.Add(new ListItem(OperType.调整结束日期.ToString(),pkValue));
this.ddlOperation.Items.Add(new ListItem(OperType.导出Excel.ToString(),pkValue));
this.ddlOperation.Items.Add(new ListItem(OperType.问卷管理.ToString(),pkValue));
}
else if (iStatusNo == (int)ZTE.EVAL.Model.EnumCollections.InvestigateStatus.已关闭)
{
this.ddlOperation.Items.Add(new ListItem(OperType.预览.ToString(),pkValue));
this.ddlOperation.Items.Add(new ListItem(OperType.导出Excel.ToString(),pkValue));
this.ddlOperation.Items.Add(new ListItem(OperType.问卷管理.ToString(),pkValue));
}
// 增加JS弹出事件
this.ddlOperation.Attributes.Add("onchange","if (ExecOperJscript('" + this.ddlOperation.ClientID + "')) return;");
{
this.ddlOperation.Items.Add(new ListItem(OperType.预览.ToString(),pkValue));
this.ddlOperation.Items.Add(new ListItem(OperType.关闭.ToString(),pkValue));
this.ddlOperation.Items.Add(new ListItem(OperType.全部跟催.ToString(),pkValue));
this.ddlOperation.Items.Add(new ListItem(OperType.调整结束日期.ToString(),pkValue));
this.ddlOperation.Items.Add(new ListItem(OperType.导出Excel.ToString(),pkValue));
this.ddlOperation.Items.Add(new ListItem(OperType.问卷管理.ToString(),pkValue));
}
else if (iStatusNo == (int)ZTE.EVAL.Model.EnumCollections.InvestigateStatus.已关闭)
{
this.ddlOperation.Items.Add(new ListItem(OperType.预览.ToString(),pkValue));
this.ddlOperation.Items.Add(new ListItem(OperType.导出Excel.ToString(),pkValue));
this.ddlOperation.Items.Add(new ListItem(OperType.问卷管理.ToString(),pkValue));
}
// 增加JS弹出事件
this.ddlOperation.Attributes.Add("onchange","if (ExecOperJscript('" + this.ddlOperation.ClientID + "')) return;");
前台:
<script language=javascript>
function ExecOperJscript(objID){
var ddl = document.getElementById(objID);
var itemText = "";
var msg = "";
for (var i = 0; i<ddl.options.length; i++) {
if (ddl.options[i].selected) { itemText = ddl.options[i].innerText; }
}
switch (itemText) {
case "删除":
msg = "你确定要删除当前调查吗?该操作不可恢复!";
break;
case "发布":
msg = "你确定要发布当前调查吗?该操作不可恢复!";
break;
case "关闭":
msg = "你确定要关闭当前调查吗?该操作不可恢复!";
break;
case "全部跟催":
msg = "你确定要跟催当前调查吗?该操作将向所有的个体发送邮件!";
break;
default:
break;
}
if (msg == "") { return true; }
return confirm(msg);
}
</script>
function ExecOperJscript(objID){
var ddl = document.getElementById(objID);
var itemText = "";
var msg = "";
for (var i = 0; i<ddl.options.length; i++) {
if (ddl.options[i].selected) { itemText = ddl.options[i].innerText; }
}
switch (itemText) {
case "删除":
msg = "你确定要删除当前调查吗?该操作不可恢复!";
break;
case "发布":
msg = "你确定要发布当前调查吗?该操作不可恢复!";
break;
case "关闭":
msg = "你确定要关闭当前调查吗?该操作不可恢复!";
break;
case "全部跟催":
msg = "你确定要跟催当前调查吗?该操作将向所有的个体发送邮件!";
break;
default:
break;
}
if (msg == "") { return true; }
return confirm(msg);
}
</script>
愿一路奔跑不退缩,到目前一直从事.Net的B/S,C/S企业应用研发