ascx 内代码
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ry_sel.ascx.cs" Inherits="WebApplication2.ry_sel" %>
<script src="Jquery-1.8.3.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#divChkList :checkbox").each(function () {
$(this).click(function () {
var $txtList = $("#txtList2");
if (this.checked) {
// $txtList.val($txtList.val() + $(this).next().text() + ",");
$txtList.val($txtList.val() + $(this).parent("span").attr("alt") + ",");
}
else {
$txtList.val($txtList[0].value.replace($(this).parent("span").attr("alt") + ',', ''));
}
});
});
});
</script>
<div style="width:400px;height:300px;margin:0 auto;">
<div id="divMulti">
<asp:TextBox ID="txtList2" runat="server" Width="286px" TextMode="MultiLine"></asp:TextBox>
<div id="divChkList">
<asp:CheckBoxList ID="chkList" runat="server" RepeatLayout="Table" RepeatDirection="Vertical">
</asp:CheckBoxList>
</div>
</div>
</div>
aspx 引用ascx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<%@ Register Src="~/ry_sel.ascx" TagName="RySel" TagPrefix="uc2" %>
<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc2:RySel ID="RySel" runat="server" />
</div>
</form>
</body>
</html>