I have web user control, on which i am using updatepanel. Inside the updatepanel there is listbox control, and i am using client script to add dates in it.
I am getting Invalid postback error on postback (when i click on the save button). Error is thrown before page pre render.
_endPostBack: function PageRequestManager$_endPostBack(error, executor, data) {
if (this._request === executor.get_webRequest()) {
this._processingRequest = false;
this._additionalInput = null;
this._request = null;
}
var eventArgs = new Sys.WebForms.EndRequestEventArgs(error, data ? data.dataItems : {}, executor);
Sys.Observer.raiseEvent(this, "endRequest", eventArgs);
if (error && !eventArgs.get_errorHandled()) {
throw error;
}
},
Here is the script for adding values in the listbox control.
function checkValue(el) {thrown
var txt = $("span[id$=spVisitDates] input[type=text]");
var svc = $(txt).val()
var lst = $('#lstVisitDates');
var options = $('#lstVisitDates option');
var alreadyExist = false;
$(options).each(function () {
if ($(this).val() == svc) {
alert("Item alread exists");
alreadyExist = true;
return;
}
});
if (!alreadyExist)
$(lst).find("option").attr("selected", false);
$(lst).append('<option value="' + svc + '" selected="selected">' + svc + '</option>');
$("#lstVisitDates").html($("#lstVisitDates option").sort(function (a, b) {
return parseDMY($(a).val()) < parseDMY($(b).val()) ? -1 : 1;
}));
}
Listbox control;
<asp:ListBox runat="server" ID="lstVisitDates" Width="220px"
ClientIDMode="Static" SelectionMode="Multiple"></asp:ListBox>
I have tried the the following sub but no success;
Protected Overrides Sub Render(writer As HtmlTextWriter)
For Each item As ListItem In lstVisitDates.Items
Page.ClientScript.RegisterForEventValidation(lstVisitDates.UniqueID, item.Value)
Next
MyBase.Render(writer)
End Sub
I think webpage doesn't know about the listbox values and that is why it is throwing error message.
ADDED
I have managed to save the listbox values in the hidden field in comma separated format, and emptying the listbox on button save click event and adding values back to list back after postback.
I don't know if this is a best way of doing it. Is there any other way?