Click here to Skip to main content
15,907,906 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: E-mail validation stupidity Pin
David O'Neil26-Jun-23 14:08
professionalDavid O'Neil26-Jun-23 14:08 
GeneralRe: E-mail validation stupidity Pin
Sander Rossel10-Jun-23 5:17
professionalSander Rossel10-Jun-23 5:17 
GeneralRe: E-mail validation stupidity Pin
trønderen10-Jun-23 7:06
trønderen10-Jun-23 7:06 
GeneralRe: E-mail validation stupidity Pin
Nelek10-Jun-23 11:41
protectorNelek10-Jun-23 11:41 
GeneralRe: E-mail validation stupidity Pin
honey the codewitch21-Jun-23 3:23
mvahoney the codewitch21-Jun-23 3:23 
GeneralRe: E-mail validation stupidity Pin
David O'Neil26-Jun-23 14:15
professionalDavid O'Neil26-Jun-23 14:15 
GeneralRe: E-mail validation stupidity Pin
Jeremy Falcon27-Sep-23 3:23
professionalJeremy Falcon27-Sep-23 3:23 
GeneralASP.Net webforms and disabled controls Pin
DerekT-P23-May-23 12:17
professionalDerekT-P23-May-23 12:17 
Well, maybe this isn't weird, and it's relating to ASP.Net Webforms so of no relevance to most of you anyway... but even though I've been using ASP.Net webforms for donkey's years, this is something I'd not realised / understood until just now.

I have a form on which some of the fields may be disabled, depending on some rather complex logic. Some of the fields are disabled dependent on one of several statuses of a business object; others are disabled depending on a boolean flag that is available client-side. Some are dependent on both tests.

I was finding that when posting back, ONE of the fields was "losing" it's value, and the underlying database was getting an empty value. (Fortunately auditing at the database level was tracking the changes in values, so in those cases it happened in the live system I was able to restore via the audit trail. I knew it would be useful!) Debugging in VS it was apparent that although both fields were disabled (and had the disabled="disabled" attribute), one was empty right at the start of the page_load event, whilst the other had the value expected. I know that disabled fields aren't posted back as part of the HTTP post, but ASP.Net was "restoring" the value (I understand through ViewState). What I couldn't figure out was why ASP.Net was restoring some disabled fields, but not others.

Eventually I noticed that the one that had the expected value had aspNetDisabled in the CSS class attribute client-side (as well as my own class name). Investigating showed that ASP.Net adds this attribute when the field is set to disabled at the server.
It turns out that my code, which had evolved over years, had one set of "disabling" rules implemented server-side, by setting field.Enabled = false ... but the field that was returning blank, was getting set disabled CLIENT side. It therefore didn't have the aspNetDisabled CSS class.

By moving the client-side logic to disable that field across to the server, the CSS class was being set and ASP.Net was restoring the value from ViewState. (Fairly obviously, just adding the aspNetDisabled classname at the client won't do the trick, as the classname doesn't get posted back).

I know, it's one of those things I should have known, and I know, too, that I should be doing things like enabling fields consistently - either client-side or server-side. My original code did it server-side, but that involved writing a line of code for each control. The later additions did it client-side because there were quite a few controls involved, and it was much simpler to just add a CSS class to each one, then use JQuery to disable ALL fields with that CSS class.
Telegraph marker posts ... nothing to do with IT
Phasmid email discussion group ... also nothing to do with IT
Beekeeping and honey site ... still nothing to do with IT

GeneralRe: ASP.Net webforms and disabled controls Pin
MarkTJohnson24-May-23 4:32
professionalMarkTJohnson24-May-23 4:32 
GeneralRe: ASP.Net webforms and disabled controls Pin
Herman<T>.Instance7-Jun-23 23:20
Herman<T>.Instance7-Jun-23 23:20 
RantAnother Visual Studio Update, Another Level of Ineptitude. Pin
Rick York17-May-23 21:00
mveRick York17-May-23 21:00 
GeneralRe: Another Visual Studio Update, Another Level of Ineptitude. Pin
Richard Deeming17-May-23 21:28
mveRichard Deeming17-May-23 21:28 
GeneralRe: Another Visual Studio Update, Another Level of Ineptitude. Pin
RickZeeland17-May-23 22:08
mveRickZeeland17-May-23 22:08 
GeneralRe: Another Visual Studio Update, Another Level of Ineptitude. Pin
Herman<T>.Instance7-Jun-23 23:39
Herman<T>.Instance7-Jun-23 23:39 
GeneralRe: Another Visual Studio Update, Another Level of Ineptitude. Pin
Jo_vb.net18-May-23 1:07
mvaJo_vb.net18-May-23 1:07 
GeneralRe: Another Visual Studio Update, Another Level of Ineptitude. Pin
Rick York9-Aug-23 5:37
mveRick York9-Aug-23 5:37 
GeneralRe: Another Visual Studio Update, Another Level of Ineptitude. Pin
Dave Kreskowiak9-Aug-23 7:54
mveDave Kreskowiak9-Aug-23 7:54 
GeneralRe: Another Visual Studio Update, Another Level of Ineptitude. Pin
Rick York24-Aug-23 11:10
mveRick York24-Aug-23 11:10 
GeneralRe: Another Visual Studio Update, Another Level of Ineptitude. Pin
Mike Hankey26-Aug-23 4:36
mveMike Hankey26-Aug-23 4:36 
GeneralRe: Another Visual Studio Update, Another Level of Ineptitude. Pin
Slacker00729-Aug-23 5:38
professionalSlacker00729-Aug-23 5:38 
GeneralRe: Another Visual Studio Update, Another Level of Ineptitude. Pin
Mike Hankey29-Aug-23 6:01
mveMike Hankey29-Aug-23 6:01 
GeneralRe: Another Visual Studio Update, Another Level of Ineptitude. Pin
Graeme_Grant29-Aug-23 19:14
mvaGraeme_Grant29-Aug-23 19:14 
GeneralRe: Another Visual Studio Update, Another Level of Ineptitude. Pin
MarkTJohnson30-Aug-23 2:40
professionalMarkTJohnson30-Aug-23 2:40 
GeneralRe: Another Visual Studio Update, Another Level of Ineptitude. Pin
Graeme_Grant10-Oct-23 23:53
mvaGraeme_Grant10-Oct-23 23:53 
GeneralPossibly the hottest mess I've seen in some time Pin
honey the codewitch2-Apr-23 19:26
mvahoney the codewitch2-Apr-23 19:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.