Posts

Showing posts from September, 2009

How To Set The Value Attribute Of An ASP.NET RadioButton In Server-Side Code

Recently I ran into a situation wherein I needed to set the value attribute of a radio button rendered via an ASP.NET RadioButton control -- except I found there was no Value property. I attempted to set it via the InputAttributes property of the control, but this didn't work either -- if I set it using the value key, my value would be ignored and replaced with the server-side ID of the control (which is what ASP.NET uses as the value attribute by default), and if I added a value attribute this way, it would add an additional value attribute, giving me two in the same control. The solution was actually a simpler approach: merely setting the value using the control's Attributes property (not InputAttributes ). Here's an example: rdoButton.Attributes["value"] = "somevalue";

How To Get The Selected RadioButton From A List Of Element IDs Using jQuery

I've been doing some work with jQuery lately and now that I've begun digging into it am truly impressed at how much you can do with it so easily. Here's a quick line of code that will take a string of element IDs belonging to RadioButtons, find the one that's selected, and display an alert box with it's value: alert("Selected radio button value: " + $(radioButtonIds).filter(":checked").get(0).value); The format of the string containing the RadioButton IDs would look something like this: "#rdoFirstChoice, #rdoSecondChoice, #rdoThirdChoice"

Crazy Internal Server Error When Developing With WCF and AJAX with jQuery

I've been doing some development lately involving calling WCF services from client-side script using jQuery's ajax function, and ran into some strange behavior. I had some code written that would run successfully without error, but then added some additional, un-related code, which would also attempt to call a WCF service via jQuery and AJAX. The original, working code remained untouched. The new code would be unsuccessful -- however, the old, previously working code would now also fail. The error was Error 500, Internal Server Error . Stopping and restarting the development server didn't solve the issue, nor did exiting and restarting Visual Studio. Even rebooting my machine didn't help. It just didn't make any sense. I finally resolved the problem by deleting the Temporary ASP.NET files for the site. By default, these are located in C:\WINDOWS\Microsoft.NET\Framework\(Framework Version)\Temporary ASP.NET Files , in a sub-folder matching the name of your site. Not...

How To Easily Convert Strings to Mixed Case (aka Title Case, aka Proper Case) in C#

I found a very easy way to convert strings to mixed case (aka Title Case, aka Proper Case) in C# today. The String class does not have a method to do this, but the TextInfo class of the System.Globalization namespace does -- the ToTitleCase() method. An important thing to note is that it doesn't work on strings that are all upper case, so convert the string to lower case first to make it work. See the example below, where sTheStringYouWannaConvert represents the string you want to convert (go figure): string sMixedCaseString = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(sTheStringYouWannaConvert.ToLower()); It's just that easy. :)