My listbox contains 2 buttons to move items up and down. When shifting the position of pre-bound items, everything functions as expected. However, if I try to add a new item from a textbox, shift its position, and then save the form, an error arises. The error message states that there is an issue with postback or callback arguments validation. Could someone provide guidance on resolving this without compromising security features? Thank you.
This snippet shows my JavaScript function for moving items up:
function moveUp() {
// get the list box
var lb = document.getElementById("<%=uilstMemTypeTier.ClientID%>");
// ignore if less than 2 items are present
if (lb.length < 2) return false;
// check if the first item is selected to prevent further movement
if (lb.options[0].selected) return false;
var tempOpt;
for (i = 1; i < lb.length; i++) {
if (lb.options[i].selected) {
// store previous option in temporary variable
tempOpt = new Option(lb.options[i - 1].value, lb.options[i - 1].value);
// move current item back one space
lb.options[i - 1] = new Option(lb.options[i].value, lb.options[i].value);
lb.options[i - 1].selected = true;
// place previous option in current position
lb.options[i] = tempOpt;
}
}
repopulateHiddenFieldDefaultsFromListBox();
repopulateHiddenFieldListItemsFromListBox();
}
function repopulateHiddenFieldDefaultsFromListBox() {
// get the list box
var lb = document.getElementById("<%=uilstMemTypeTier.ClientID%>");
// get the hidden field
var hf = document.getElementById("<%=hf_listBasedFields_defaultItems.ClientID%>");
for (i = 0; i < lb.length; i++) {
if (lb.options[i].selected) hf.value += lb.options[i].value + delim;
}
}
function repopulateHiddenFieldListItemsFromListBox() {
// get the list box
var lb = document.getElementById("<%=uilstMemTypeTier.ClientID%>");
// get the hidden field
var hf = document.getElementById("<%=uihdnlistBasedFieldsListItems.ClientID%>");
// loop through the list box and update the hidden field
hf.value = "";
for (i = 0; i < lb.length; i++) hf.value += lb.options[i].value + delim;
}
Error message:
The system has detected an invalid postback or callback argument related to event validation. For enhanced security, it is essential to ensure that data comes from reliable sources for postback or callback events. It is recommended to use ClientScriptManager.RegisterForEventValidation method to register postback or callback data for thorough validation.