Friday 20 February 2015

asp:DropDownList - invalid postback or callback argument

I was getting this exception when selecting what looked like a perfectly valid ASP.NET drop down list option.

This error is usually caused by something changing the contents of the drop down before postback, which gets .NET very confused.

In my case, it was due to white space in some of the drop down entries being bound. Using String.Trim() cleared this up.

Strangely, changing from a .NET drop down to a standard drop down (select tag) caused my getters to fetch an empty string instead of my value.

This sort of thing happens a lot with Umbraco properties, because quite a few of them are auto-padded with white space. Calling Trim() is a good practice in situations where you think you might get unnecessary padding.