Invalid postback or callback argument. Event validation is enabled using ''

后端 未结 30 1358
生来不讨喜
生来不讨喜 2020-11-22 05:08

I am getting the following error when I post back a page from the client-side. I have JavaScript code that modifies an asp:ListBox on the client side.

How do we fix

相关标签:
30条回答
  • 2020-11-22 05:25

    If you are using gridview and not bind gridview at pageload inside !ispostback then this error occur when you click on edit and delete row in gridview .

     protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
            bindGridview();
            }
    
    0 讨论(0)
  • 2020-11-22 05:26

    This error will show without postback

    Add code:

    If(!IsPostBack){
    
     //do something
    
    }
    
    0 讨论(0)
  • 2020-11-22 05:27

    A simple solution for this problem is to use the IsPostBack check on your page load. That will solve this problem.

    0 讨论(0)
  • 2020-11-22 05:29

    if you change UseSubmitBehavior="True" to UseSubmitBehavior="False" your problem will be solved

    <asp:Button ID="BtnDis" runat="server" CommandName="BtnDis" CommandArgument='<%#Eval("Id")%>' Text="Discription" CausesValidation="True" UseSubmitBehavior="False" />
    
    0 讨论(0)
  • 2020-11-22 05:31

    You are really going to want to do 2 or 3, don't disable event validation.

    There are two main problems with adding items to an asp:listbox client side.

    • The first is that it interferes with event validation. What came back to the server is not what it sent down.

    • The second is that even if you disable event validation, when your page gets posted back the items in the listbox will be rebuilt from the viewstate, so any changes you made on the client are lost. The reason for this is that a asp.net does not expect the contents of a listbox to be modified on the client, it only expects a selection to be made, so it discards any changes you might have made.

    The best option is most likely to use an update panel as has been recommended. Another option, if you really need to do this client side, is to use a plain old <select> instead of an <asp:ListBox>, and to keep your list of items in a hidden field. When the page renders on the client you can populate it from a split of your text field contents.

    Then, when you are ready to post it, you repopulate the hidden field's contents from your modified <select>. Then, of course, you have to split that again on the server and do something with your items, since your select is empty now that it's back on the server.

    All in all it's a pretty cumbersome solution that I would not really recommend, but if you really have to do client-side modifications of a listBox, it does work. I would really recommend you look into an updatePanel before going this route, however.

    0 讨论(0)
  • 2020-11-22 05:31

    you try something like that,in your .aspx page

    add

    EnableEventValidation="false"

    you feel free to ask any question!

    0 讨论(0)
提交回复
热议问题