Вопрос

This is the error:

Invalid postback or callback argument.  Event validation is enabled using 
<pages enableEventValidation="true"/> 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.

And this is what I'm doing:

aspx:

protected void Page_Load(object sender, EventArgs e)
{
        if (!IsPostBack)
        {
                myUserControl.DataBind();
        }
 }

usercontrol:

 public override void DataBind()
 {

        ddlContacts.DataSource = SessionHandler.Contacts;
        ddlContacts.DataValueField = "Id";
        ddlContacts.DataTextField = "Name";
        ddlContacts.DataBind();

        ddlOrderbillto.DataSource = SessionHandler.Contacts;
        ddlOrderbillto.DataValueField = "Id";
        ddlOrderbillto.DataTextField = "Name";
        ddlOrderbillto.DataBind();

        ddlState.DataSource = SessionHandler.FederalStates;
        ddlState.DataTextField = "Name";
        ddlState.DataValueField = "Id";
        ddlState.DataBind();

        if (Info.Id > 0)
        {
           //load info
        }
 }

As you can see I have 2 dropdown lists that I load ddlContacts and ddlOrderbillto and everything worked like it was supposed to. As soon as I added ddlState all the sudden I get the error I mentioned above. I've tried putting it inside an update panel and nothing. If I comment the ddlState datasource, databinding then it works but obviously I'm left with no states :(

Help please?

EDIT: I have 2 other dropdown lists "ddlCounties" and "ddlCity" which when page databinds they are blank, but upon changing "ddlState" they get populated through jquery. So from what I've read is that because they are not loaded originally then this could be the error?

Это было полезно?

Решение

change EnableEventValidation="false" on the top of the page..!! for it to work..but it is not a good method..!!

When the EnableEventValidation property is set to true, ASP.NET validates that a control event originated from the user interface that was rendered by that control. A control registers its events during rendering and then validates the events during postback or callback handling. For example, if a list control includes options numbered 1, 2, or 3 when the page is rendered, and if a postback request is received specifying option number 4, ASP.NET raises an exception. All event-driven controls in ASP.NET use this feature by default. If you write client script that changes a control in the client at run time, you might have to use the RegisterForEventValidation method in order to avoid false event validation errors.

check this link

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top