I am trying to create a web form where a user uses some drop down information and then a container appears and the user has to select one of the two radio options OK or NOT OK.
The web form is created dynamically using asp:placeholder in the frontend. So the number of placeholders which will come depends on the entries in database.
So lets assume 5 images with buttons pop up, the user needs to select at least 1 button per container and also for any container if the user selects a NOT OK, the value should go as 1 in DB. I have tried 3-4 options but none of them seem to work.
How it is grouped in the generateLayout method
How I did the recursive option.
TIA
I have tried using radio.attributes, tried using Javascript in the front end, using a recursive control method for radios. Nothing seems to work.
int status = hiddenStatus.Value == "1" ? 1 : 0;
string groupName = toolName;
RadioButton okButton = new RadioButton
{
ID = "RadioButtonOk_" + toolName,
CssClass = "RadioButtonOk",
GroupName = groupName,
Text = "OK"
};
okButton.Attributes.Add("data-tool", toolName);
RadioButton nokButton = new RadioButton
{
ID = "RadioButtonNok_" + toolName,
CssClass = "RadioButtonNok",
GroupName = groupName,
Text = "NOK"
};
nokButton.Attributes.Add("data-tool", toolName);
Panel okPanel = new Panel { CssClass = "radio-button-wrapper" };
okPanel.Controls.Add(okButton);
Panel nokPanel = new Panel { CssClass = "radio-button-wrapper" };
nokPanel.Controls.Add(nokButton);
Panel radioPanel = new Panel { CssClass = "radio-buttons" };
radioPanel.Controls.Add(okPanel);
radioPanel.Controls.Add(nokPanel);
Panel detailsPanel = new Panel { CssClass = "tool-details" };
detailsPanel.Controls.Add(toolNameLabel);
detailsPanel.Controls.Add(header);
detailsPanel.Controls.Add(description);
detailsPanel.Controls.Add(radioPanel);
groupPanel.Controls.Add(image);
groupPanel.Controls.Add(detailsPanel);
ToolContainer.Controls.Add(groupPanel);
<script type ="text/javascript">
function validateInspection() {
var toolGroups = {};
var radios = document.querySelectorAll("input[type='radio']");
var nokSelected = false;
for (var i = 0; i < radio.length; i++) {
var group = radios[i].getAttribute("data-tool");
if (!group) continue;
if (!toolGroups[group]) {
toolGroups[group] = { ok: false, nok: false, selected: false };
}
if (radios[i].checked) {
toolGroups[group].selected = true;
if (radios[i].value.toUpperCase() == "NOK" || radios[i].id.toUpperCase().indexOf("NOK") !== -1) {
nokSelected = true;
}
}
}
}
var allSelected = true;
for (var key in toolGroups) {
if (!toolGroups[key].selected) {
allSelected = false;
break;
}
}
if (!allSelected) {
alert("Please select OK or NOK for every tool");
return false;
}
var statusField = document.getElementById("<%= hiddenStatus.ClientID %>");
if (statusField) {
statusField.value = nokSelected ? "1" : "0";
}
return true;
}
</script>


