您的位置:首页 > Web前端 > JavaScript

如何遍历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 = "";

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: