views:

258

answers:

1

I really hate this error, because it can be so hard to pin point.

In this case, I have a page with a user control on it that contains a gridview. When a button is clicked to view one of the records in the gridview, a pop-up window (in the form of a modal dialog) opens allowing the user to edit the fields. Then, when the pop-up is closed, the button's server side code is fired, ultimately leading to a line of code that calls GridView1.databind();. When this line of code is fired, I will get the invalid postback error. If this one line is commented out, I don't get the error. This happens whether or not I actually make any changes in the pop-up. And at no point is there client-side code modifying the values in my controls.

So, it seems that something has changed with the gridview that it doesn't like. I think it might have to do with the ObjectDataSource that it's using. I noticed that before the gridview is databound, the ODS InputParameters are set using Session values. In any case, something is changing there that's causing this error. So, I tried doing :

protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
    Page.ClientScript.RegisterForEventValidation(GridView1.UniqueID);
    base.Render(writer);
}

I also tried registering the ODS. But neither approach solved my problem.

What should I do? I'm completely stumped at this point.

A: 

I'm pretty sure that the invalid postback error comes from putting your call to the databinding function in the Page_Load.

matthew_360