I have some trouble finding a particular Checkbox. In a dynamic asp.net CheckboxList with approximately 100 Checkboxes, I have a right click context menu and want to get the particular Checkbox on which I opened the context menu.
Here is my javascript/JQuery:
<script type="text/javascript">
function ShowMenu(control, e) {
var posx = e.clientX + window.pageXOffset + 'px';
var posy = e.clientY + window.pageYOffset - 10 + 'px';
document.getElementById(control).style.position = 'absolute';
document.getElementById(control).style.display = 'inline';
document.getElementById(control).style.left = posx;
document.getElementById(control).style.top = posy;
var parent = document.getElementById('<%= cbl_Machines.ClientID%>');
};
function HideMenu(control) {
document.getElementById(control).style.display = 'none';
};
$(document).on('click', '#divSelectAll', function () {
$("INPUT[type='checkbox']").prop('checked', true);
__doPostBack();
});
$(document).on('click', '#divDeselectAll', function () {
$("INPUT[type='checkbox']").prop('checked', false);
__doPostBack();
});
$(document).on('click', '#divAddMachine', function () {
window.location.replace("../MemberPages/CreateMachine.aspx");
});
$(document).on('click', '#divModifyMachine', function () {
alert('<%=cbl_Machines.ClientID%>');
});
</script>
And here is my HTML:
<body>
<div id="leftBox" onmousedown="HideMenu('contextMenu');"oncontextmenu="ShowMenu('contextMenu',event);">
<asp:CheckBoxList ID="cbl_Machines" Width="100%" RepeatLayout="Table" CssClass="cblmachines" runat="server" AutoPostBack="True" OnSelectedIndexChanged="cbl_Machines_SelectedIndexChanged" />
<div style="padding: 0px 5px; border: 1px solid black; border-top-style: none">
<asp:Button ID="btn_CreateMachine" Width="33%" runat="server" Text="Add Machine" OnClick="btn_CreateMachine_Click" />
<asp:Button ID="btn_ModifyMachine" Width="32%" runat="server" Text="Modify Machine" OnClick="btn_ModifyMachine_Click" />
<asp:Button ID="btn_DeleteMachine" Width="32%" runat="server" Text="Delete Machine" OnClick="btn_DeleteMachine_Click" />
</div>
</div>
<div style="display: none;" id="contextMenu" onmouseup="HideMenu('contextMenu');">
<table border="0" style="border: thin solid #808080; cursor: default; width: 150px; background-color: white">
<tr>
<td>
<div id="divSelectAll" class="ContextItem">Select All</div>
</td>
</tr>
<tr>
<td>
<div id="divDeselectAll" class="ContextItem">Deselect All</div>
</td>
</tr>
<tr>
<td>
<div id="divAddMachine" class="ContextItem">Add Machine</div>
</td>
</tr>
<tr>
<td>
<div id="divModifyMachine" class="ContextItem">Modify Machine</div>
</td>
</tr>
</table>
</div>
</body>
And last but not least my Code Behind
if (!Page.IsPostBack)
{
Configuration.DeserializeFromXMLMachines();
var orderedList = Configuration.ManagedMachines.OrderBy(x => x.MachineName);
foreach (var item in orderedList)
{
cbl_Machines.Items.Add(item.MachineName);
}
}
When I right click in the 'leftBox' Div the following
Context Menu appears
And now when I click on Modify Machine I only need the value of this checkbox where the Context Menu opens. In this Case the one with the value Test24.
Thanks in advance