<script type="text/javascript" language="javascript">
function setupMyCheckBox() { var chkMyCheckBox = document.getElementById('<%=chkMyCheckBox.ClientID%>');
//...do something with the object here ...
But if the field is inside a formview for example, this is how you would reference it:
<script type="text/javascript" language="javascript">
function setupMyCheckBox() { var chkMyCheckBox = document.getElementById('<%=frvMyForm.FindControl("chkMyCheckBox").ClientID%>');
//...do something with the object here ...
One thing to keep in mind. If you have different formview or gridview modes. (such as view, edit and insert). Then you must setup a "dummy hidden control" in each mode's section in order to avoid an object not found error in the javascript code. You can set it to be a literal or if you are referencing it in code-behind, set it to be the same type as the original field but hidden. Here is an example when setting it as a literal. Note this field has no use except to avoid an error when running the FindControl method in the javascript.<asp:Literal ID="chkMyCheckBox" runat="server" Visible="false">asp:Literal>