Friday, 9 November 2012

Handling unchecked checkboxes on form post


Wow - 2 years since i made a post on here!Oops. Guess i've been a little busy.

Anyway - i thought i just had to post this little nugget as it had me head scratching for a while.

You my be looking for a solution to any of the following:

Handling unchecked checkboxes on form post
Checkboxes missing from postback in asp.net web forms
Checkboxes missing from form on postback

or something of a similar ilk! Chances are its probably the same issue.

Except its not an issue - it seems its by design unfortunately.  No idea who made this decision but when a checkbox is not checked it is not posted back to the server in a form post!

I came across this because i was dynamically building the form and populating a database from what came back and stuff wasnt getting updated when i unticked the checkboxes.

After a lot of debugging trying to suss the problem i discovered the issue as outlined above.

Anyway to cut to the chase... the way to solve this - or at least how i solved this was to add a hidden field with the same NAME (not ID) just before the checkbox.

To set the name you will have to do a little messing about as its not a property on the server control.  My situation was unique as i had the controls on a user control so i took the UniqueID of the usercontrol, replaced the separator '_' with the ClientIDSeparator '$' and then added $checkboxname to the end.

The next thing you will have to do is remove a comma ',' from the value in the form as multiple items with the same name create an array of controls on the form that all get placed into the value.

So just strip that out and you should now get a form item with the name of the checkbox as an empty string even when the checkbox is unchecked!

Hope you understand that.  Like i said my situation was unique so i cant really drop source code in but if you need any help with your situation then add a comment and i'll try to help.


Thursday, 11 November 2010

My Idea for Microsoft Kinect - A Virtual World Just Like Lawnmower Man

Remember the film Lawnmower Man where the guy went into a virtual world? See the bottom of this post for the trailer. Well maybe Microsoft Kinect could fetch something like this to the masses.

I've been having a think about the sort of games that could work well with this technology and when you think about how it can recognise you and your voice, understands depth, motion and your mood etc. then why not create a virtual world.

Everthing I have seen up to now has involved everyone jumping up and down infront of the TV. But what if you put on a set of TV glasses and the Kinect placed you in the center of the game? If you held your hand up infront of your face Kinect could show your hand right there infront of you via the screen! Freaky! :o)

Developers etc will obviously have to get to grips with the platform but wow this thing could be huge. You could interact with people/characters/other players on xbox live right there in the game all in a virtual world.

You could also use the platform to create your own 'self' in someone elses system over xbox live for video/face to face chat! This again will be amazing but freaky but I can see it happening.

And how about a good old punch up game where you actually have a ruck with your friends in this virtual world. I dont know the quality of the depth sensor to be able to make out facial features but with some image wizardry im sure a half decent image of a person coudl be overlayed onto the virtual person.

I do wonder about safety though if you start wearing glasses and wondering aroudn this virtual world. A shin into a non virtual coffee table wouldn't be too clever.

I've not got the new Kinect yet and think it will go on the xmas list. I was quite excited by the Natal videos several months ago but had forgotten about it really since. However after looking at it more today im quite looking forward to having a play and seeing just where this puppy goes! Looking at the messages on twitter and facebook it seems people are giving it the thumbs up!

I know one thing for sure anyway... it wont be difficult to lay your hands on a Wii this xmas! They will be ten a penny on fleabay!

Anyway - heres lawnmowerman which was a pretty good film at the time....

Monday, 9 August 2010

ASP.Net Web Form Routing - Routing Problem

I have put together a web application project that made use of ASP.Net web form routing but I had some strange behaviour on a certain route.

The route i had added to the routes tables was:

routes.Add("Admin", new Route
("Admin",
new PageRouteHandler("~/Admin/help.aspx", true)));

This was to point to a the help.aspx page in the admin folder.

The Problem

When i attempted to browse to this route -

domain.com/admin

Symptoms

Rather than the page all i got was a directory listing in the web page.

Workaround

It appears the routing engine doesnt like a route value to have the same name as the folder it is pointing to.

All I had to do was rename the folder (or route value eg. domain.com/admin/help) and it all started working again.

Im not sure if this is a bug or a feature!

Please post a comment if you know what thy happened.

Thanks

Friday, 16 April 2010

Visual Studio 2010 Finally Released

So Visual Studio 2010 has finally been released. I downloaded our MSDN copy yesterday so today I will be installing in the background while i get on with other stuff - it looks a monster install!

Big thumbs up to the change in versions! What used to be multiple versions to purchase (Architect, Tester, Database, Developer) are now wrapped into Ultimate for us Team Edition users!

I'll let you know how I get on with it as I look at all the new goodies.

Just one last thing - I often recommend LearnVisualStudio.net not only as I am a very happy lifetime member and affiliate but because I truly believe you get a lot for your money - especially if you are just starting out - its where I started out and still keep going back for their new videos.

Anyway back to my original point - they have gone away and re-done their entire Visual Studio for Beginners library for Visual Studio 2010. That is 72 new videos! If you are looking to get the complete training package for peanuts then look no further!