ASP.Net Data Controls + JavaScript Hell

Either my Google skills are considerably lacking tonight, or very few people have tried to do what I am.

I have a web form that contains a DataRepeater, each ItemTemplate containing three textboxes (Quantity, Price, Total), and a DropDownList. All these are easily manipulated using the DataRepeater’s Items property, and they’re all easily assigned to after calling DataBind() by making use of the ItemDataBound event.

That’s been working fine for me for quite some time; Now here’s where the problem comes in: I’ve been revamping the user interface for TB to minimize postbacks and unneccesary clutter. In this case, I don’t want any extra empty rows; an empty row will automatically be added as soon as you fill in the last one using JavaScript and Scriptaculous, similar to the behavior present in SQL Server Management Studio or Enterprise Manager for adding rows.

Apparently not many people have tried to do this, or if they have, no one has posted about it anywhere online that I can find.

DataRepeaters, the lightest weight of the data controls available, makes use of the Viewstate to persist information. Usually, not a big deal. If you’re trying to dynamically add rows with Javascript, then it becomes a major problem. Making your field names simply follow the correct naming pattern’s doesn’t work because of the need for the control information to be stored in the Viewstate, and no Javascript code is going to manipulate that.

That’s when you have to scrap the functionality that DataRepeater provides for parsing the data on PostBack and in all actuality, it isn’t bad to do at all, but it seems like a bit of a hack.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>