ASP.NET and JavaScript

So I’m converting an old web application to .NET at the moment and running in to a few problems. It’s not really ASP.NET’s fault. The main trouble is that I have to link into the horrible SAP ITS system, which combines all the readability and user-friendliness of Forth with the sheer power of assembler. The main problem is that ITS doesn’t let you do things like pass arrays of values into it, so in both the original and translated versions I’m having to do horrible hacks with JavaScript to get things done.

The specific problem I’ve just had is on one page where I have two list boxes, and double-clicking on an item in one box moves it to the other. This used to be done, and the results stored, in JavaScript. Now, I’m still doing it in JS but was hoping that .NET would let me pick up which items had been moved on PostBack.

It didn’t work.

Every time I stepped through the code, the list boxes were coming through completely unchanged.

Then I had a Homer-like "Doh!" moment. There’s no way ASP.NET could know I was removing stuff from the lists. The only values submitted to the form from lists are selected items, not the entire contents of the list.

Having chastised myself for not thinking of that sooner, I came up with a workaround. Simply copy the contents of a list to a hidden field, delimited with commas. Then I can use server-side ASP.NET to work out what has and hasn’t been removed.

Not pretty, and indeed the whole way of doing this isn’t the best, but I can’t change that at the moment.

This entry was posted in Computers and Internet. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s