Question Details

No question body available.

Tags

javascript ascx

Answers (1)

February 9, 2026 Score: 2 Rep: 81,127 Quality: Medium Completeness: 80%

Your Javascript code of

function validateCheckboxen(sender, args) {

var bool1 = document.getElementById('').checked; var bool2 = document.getElementById('').checked;

args.IsValid = bool1 || bool2; }

document.addEventListener("DOMContentLoaded", function () { var val = document.getElementById(''); var chk1 = document.getElementById(''); var chk2 = document.getElementById('');

if (!val || !chk1 || !chk2) return;

chk1.onclick = chk2.onclick = function () { ValidatorValidate(val); }; });

Is inside your js/validateCheckboxen.js file which is loaded by the client-side and which is not evaluated by the server, so the ids you refer to never get overriden by the actual ids. The reason why you did not get an error is that at this section

    var val = document.getElementById('');
    var chk1 = document.getElementById('');
    var chk2 = document.getElementById('');

if (!val || !chk1 || !chk2) return;

if any of the three is not found, the function returns, so it will never end up to the place where the error would occur, since getElementById returns undefined if there was no element with the id specified in the query and undefined is falsy, sot the if evaluates as false and the function returns.

A solution to the issue would be to refer to the values via variables:

function validateCheckboxen(sender, args) {

var bool1 = document.getElementById(ClientIDs.Checkbox2anonymized).checked; var bool2 = document.getElementById(ClientIDs.Checkbox1anonymized).checked;

args.IsValid = bool1 || bool2; }

document.addEventListener("DOMContentLoaded", function () { var val = document.getElementById(ClientIDs.BerechnungValidator); var chk1 = document.getElementById(ClientIDs.Checkbox1anonymized); var chk2 = document.getElementById(ClientIDs.Checkbox2anonymized);

if (!val || !chk1 || !chk2) return;

chk1.onclick = chk2.onclick = function () { ValidatorValidate(val); }; });

and having an initClientIDs function like

function initClientIDs() {
    window.ClientIDs = {
        Checkbox2anonymized: ''
        Checkbox1anonymized: '',
        BerechnungValidator: ''
    };
}

but you'll need to make sure it's executed before the validator is loaded to make sure you have all the client ids hydrated you need, like:


function initClientIDs() {
    window.ClientIDs = {
        Checkbox2anonymized: ''
        Checkbox1anonymized: '',
        BerechnungValidator: ''
    };
}
initClientIDs();

So this will actually happen:

  • initClientIDs is defined
  • initClientIDs is called, so all the ids you want to map will end up in the ClientIDs variable in the global context
  • your validator is loaded
  • by the time its functions are executed, ClientIDs is hydrated for sure and its members will successfully be referred to inside

The idea should work, albeit I have not tested the code above, so if you encounter an issue or an error, let me know in the comment-section.