1

I used a asp.net dropdownlist box and use OnSelectedIndexChanged event but when item selection has changed i am getting above error.

Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

I want a solution without disable event validation in page or web.config.

 <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" 
    OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>

if(!IsPostBack)
        {
            DropDownList1.Items.Add(new ListItem("item1", "1"));
            DropDownList1.Items.Add(new ListItem("item2", "2"));
            DropDownList1.Items.Add(new ListItem("item3", "3"));
            DropDownList1.Items.Add(new ListItem("item4", "4"));

        }

 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        var selItem = this.DropDownList1.SelectedItem; 
    }

How to resolve that exception. Any hints/sample is appreciable.

Morshed
  • 165
  • 3
  • 16
  • Have you added the if(!IsPostBack) on your every action that involves page reload, or which is called at page reload? This should prevent the error from appearing. Also you can check [this questin](http://stackoverflow.com/questions/228969/invalid-postback-or-callback-argument-event-validation-is-enabled-using-page) and you may find something appropriate for your case. It has a lot of answers. I will be curious which was the problem in your case and how did you managed to solve it! – meJustAndrew Jun 19 '16 at 23:49

1 Answers1

0

Hope you have set the event handler for OnSelectedIndexChanged event in your designer. Try setting UseSubmitBehavior property of the control to False like

UseSubmitBehavior="False"
Rahul
  • 76,197
  • 13
  • 71
  • 125
  • I do not see any property of dropdownlist. Invalid postback exception raised when selection changed. – Morshed Jun 19 '16 at 22:29
  • @Morshed, go to designer and select the said dropdown control and press F4. You will see list of all properties available. – Rahul Jun 19 '16 at 22:36