Error: Event validation is enabled using <pages enableEventValidation="true"/>

Last post 04-09-2009 9:44 AM by tinuverma. 5 replies.

Sort Posts:

  • Error: Event validation is enabled using <pages enableEventValidation="true"/>

    04-08-2009, 5:49 PM
    • Member
      67 point Member
    • tinuverma
    • Member since 05-17-2007, 1:03 AM
    • Posts 74

     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;
    }

  • Re: Error: Event validation is enabled using <pages enableEventValidation="true"/>

    04-09-2009, 12:42 AM

    Hi,

    Include EnableEventValidation="true" in page directive of your code page(ASPX page)

    Thanks,

    Khushboo Nayak

    Please Mark as Answered if this helps you.

  • Re: Error: Event validation is enabled using <pages enableEventValidation="true"/>

    04-09-2009, 2:56 AM
    Answer
    • All-Star
      17,363 point All-Star
    • imran_ku07
    • Member since 06-04-2008, 1:21 PM
    • KARACHI, PAKISTAN
    • Posts 3,172

    Actually all Possible values of Drop Down are saved in __EVENTVALIDATION

    If you add Item Dynamically and Post Back Occur, and selected item is Different than

    all the values added at server side exception occur

    Here I have suggested some tricks 

    http://forums.asp.net/p/1407104/3068431.aspx#3068568 


     

  • Re: Error: Event validation is enabled using <pages enableEventValidation="true"/>

    04-09-2009, 9:15 AM
    • Member
      67 point Member
    • tinuverma
    • Member since 05-17-2007, 1:03 AM
    • Posts 74

     Imran, thanks for explaining why I am getting this error. This is what I was looking for. Khushi, I didn't want to add the EnableEventValidation=false and not realize what was the real problem.

    Here is another question, because I am adding this new value via javascript - and not postback, how would I do something like this here:

    protected override void Render(HtmlTextWriter writer)
    {
    ClientScript.RegisterForEventValidation(DropDown1.UniqueID, "10");
    base.Render(writer);
    }

     

    Thanks again for explaining the reason.

     D

  • Re: Error: Event validation is enabled using <pages enableEventValidation="true"/>

    04-09-2009, 9:27 AM
    • All-Star
      17,363 point All-Star
    • imran_ku07
    • Member since 06-04-2008, 1:21 PM
    • KARACHI, PAKISTAN
    • Posts 3,172

    Yes this is the real Problem that you must Know all the Dynamic Value

    that are added dynamically and add this on Page Render on server.

    This is not possible to set this at Client side. 

  • Re: Error: Event validation is enabled using <pages enableEventValidation="true"/>

    04-09-2009, 9:44 AM
    • Member
      67 point Member
    • tinuverma
    • Member since 05-17-2007, 1:03 AM
    • Posts 74

     Thanks

Page 1 of 1 (6 items)