Hello Guys,
I am creating an editable dropdown list. For that, I added a "other" option to the list of values. When that is selected, a hidden text box is made visible and over lays on dropdown. the value entered there is dynamically inserted as an option in the dropdown (javascript) and the textbox is hidden again.
When I do a postback after a value has been added like this, I get the following error message.
Invalid postback or callback argument. Event validation is enabled using
<pages enableEventValidation="true"/> in configuration or <%@ Page
EnableEventValidation="true" %> in a page.
Any suggestions? Here is the code:
<div class="dropdownContainer">
<asp:DropDownList ID="ddlDropdown" CssClass="dropdown" runat="server" onchange="javascript:return manageDisplayCustomEntry(this);"/>
<div style="border:solid 1px black;display:none;" class="customValue">
<div style="text-align:right;width:100%;">
<a href="http://forums.asp.net/AddPost.aspx?ForumID=15#" onclick="javascript:return hideOtherOption(this);">x</a>
</div>
<input type="text" name="txtCustomValue"/>
<a href="http://forums.asp.net/AddPost.aspx?ForumID=15#" onclick="javascript:return addNewOptionToParent(this);">+</a>
</div>
</div>
The javascript basically does what is mentioned above ...but it's below if needed (and helpful):
function hideOtherOption(sender) {
$(sender).closest(".customValue").css("display", "none");
$($(sender).closest(".customValue")).find("input[name='txtCustomValue']")[0].value = "";
$($(sender).closest(".dropdownContainer")).find(".dropdown")[0].style.display = "";
return false;
}
function manageDisplayCustomEntry(sender) {
if (sender[sender.selectedIndex].text == "Other") {
$($($(sender).closest(".dropdownContainer")[0]).find(".customValue")[0]).css("width", $(sender).innerWidth() + 20 + "px");
$($($(sender).closest(".dropdownContainer")[0]).find(".customValue")[0]).css("display", "");
var divOverlay = $($(sender).closest(".dropdownContainer")[0]).find(".customValue")[0];
divOverlay.style.left = $(sender).position().left;
divOverlay.style.top = $(sender).position().top;
divOverlay.style.display = "block";
$(sender).css("display", "none");
}
else
$($($(sender).closest(".dropdownContainer")[0]).find(".customValue")[0]).css("display", "none");
return false;
}
function addNewOptionToParent(sender) {
$(sender).closest(".customValue").css("display", "none");
var newValue = $($(sender).closest(".customValue")).find("input[name='txtCustomValue']")[0].value;
$($(sender).closest(".customValue")).find("input[name='txtCustomValue']")[0].value = "";
var dropDown = $($(sender).closest(".dropdownContainer")).find(".dropdown")[0];
$(dropDown).css("display", "");
if (newValue.trim() != "") {
dropDown.options[dropDown.length - 1] = new Option(newValue, newValue);
dropDown.options[dropDown.length] = new Option("Other", "Other");
dropDown.options.selectedIndex = dropDown.length - 2;
}
return false;
}