29 May, 2008 in Programming by

ASP.NET "Invalid postback or callback argument." Exception Solved

;

I’ve been wracking my brains out for 2 days on this exception, until now.

I have a Web User Control that contains a GridView with some Command Buttons using an ObjectDataSource. Pretty simple. Let’s call it ActiveWidgets.ascx.

I wanted to notify the parent page when either of the command buttons where clicked in ActiveWidgets to notify other controls on the page that they need to re-bind or whatever.

Then when I’d click the Edit or Delete command button, boom, Invalid Postback exception.

I have the command buttons in a template field so I could add a javascript onclientclick confirmation to the Delete button. At first I thought this had something to do with the problem, but no.

It turns out that since I overrode DataBind in ActiveWidges.ascx, that method was getting called multiple times during the page load process. This was causing Invalid Postback exception.

Naturally I was using the DataBind method to call my logic layer to get the records to populate the GridView.

To solve the problem, I just changed my DataBind method from:

protected override void DataBind()
{
// Logic stuff
// DataBinding controls...
}
to:
public void Bind()
{
// Same Logic Stuff
// Same DataBinding controls
}

Now I know I’m the only one calling Bind and my button commands are firing perfectly.

I hope this helps you with any similar problems you may be experiencing. Please leave a comment to let me know 🙂

Share on Twitter

No Responses so far | Have Your Say!

Comments are closed.