如何遍历RadioButtonList控件并为子项添加JS验证
2011-12-12 16:08
246 查看
后台:
protected void Page_Load(object sender, EventArgs e)
{
//Session["RegistrationTitle"].ToString();//标题
//Session["Folder"].ToString();//文件夹名
if (Session["ResultList"]!=null)
{
Session["ResultList"].ToString();//字段信息
}
if (!IsPostBack)
{
//bind control type
this.rbl_Tyle.DataSource = Enum.GetNames(typeof(Common.InfoControlType));
this.rbl_Tyle.DataBind();
this.cbl_Validators.DataSource = Enum.GetNames(typeof(Common.ValidatorType));
this.cbl_Validators.DataBind();
}
//遍历RadioButtonList控件
foreach (ListItem item in rbl_Tyle.Items)
{
item.Attributes.Add("onclick", "validateRadioButtonList(this)");
}
}
前台:
<asp:RadioButtonList ID="rbl_Tyle" runat="server" RepeatDirection="Horizontal"></asp:RadioButtonList>
<asp:Label ID="LabType" runat="server" Text="" ForeColor="Red"></asp:Label>
JS脚本
function validateRadioButtonList(e) {
// var obj = e.value;
alert(e.value);
document.getElementById("<%=LabType.ClientID%>").innerHTML = "";
}
protected void Page_Load(object sender, EventArgs e)
{
//Session["RegistrationTitle"].ToString();//标题
//Session["Folder"].ToString();//文件夹名
if (Session["ResultList"]!=null)
{
Session["ResultList"].ToString();//字段信息
}
if (!IsPostBack)
{
//bind control type
this.rbl_Tyle.DataSource = Enum.GetNames(typeof(Common.InfoControlType));
this.rbl_Tyle.DataBind();
this.cbl_Validators.DataSource = Enum.GetNames(typeof(Common.ValidatorType));
this.cbl_Validators.DataBind();
}
//遍历RadioButtonList控件
foreach (ListItem item in rbl_Tyle.Items)
{
item.Attributes.Add("onclick", "validateRadioButtonList(this)");
}
}
前台:
<asp:RadioButtonList ID="rbl_Tyle" runat="server" RepeatDirection="Horizontal"></asp:RadioButtonList>
<asp:Label ID="LabType" runat="server" Text="" ForeColor="Red"></asp:Label>
JS脚本
function validateRadioButtonList(e) {
// var obj = e.value;
alert(e.value);
document.getElementById("<%=LabType.ClientID%>").innerHTML = "";
}
相关文章推荐
- js如何获取asp.net服务器端控件的值(label,textbox,dropdownlist,radiobuttonlist等)
- 如何为js控件添加事件监听
- asp.net中服务器控件如何添加客户端的js事件?
- js如何向数组里面添加数据和遍历出来数组里面的内容
- 如何在web控件中添加Js方法
- 给服务器控件添加前台js验证,使得通过了前台js验证才执行相应的服务器端操作(OnClientClick)
- 使用Ext.net时如何遍历Panel或者FormPanel中Content标签下的控件,并进行验证
- js获取asp.net服务器端控件Label,TextBox,RadioButtonList,DropDownList的值
- WPF如何后台动态添加控件的右键菜单
- 1. 为需要的页面,添加 JS 文件.思想是在页面提交的时候判断控件的正则表达式属性,
- js如何控制select控件(下拉列表)
- JavaScript 如何给js 空对象动态添加未知属性和值?
- 在UAP中如何通过WebView控件进行C#与JS的交互
- js通用验证,给表单添加属性!
- ASP.NET开发中主要的字符验证方法-JS验证、正则表达式、验证控件、后台验证
- jQuery验证控件jquery.validate.js使用说明+中文API
- 动态添加的控件(如TextView)如何居中?如何相对对齐?
- jQuery验证控件jquery.validate.js使用说明+中文API
- 使用masterpage的情况下如何使用js实现repeater控件里的checkbox全选
- ASP.NET WEB控件如何添加控件事件的响应函数