Thursday, December 16, 2010

Control.Find<T>(string id) Extension Method

For my current project, I am constantly using FindControl to dynamically locate a child control within a parent control. Instead of constantly typing this:

   1: DropDownList dropDownList = employeeListView.FindControl("regionDropDownList") as DropDownList;

I created an extention method to prettify my code:

   1: public static class ControlExtensions
   2: {
   3:     public static T Find<T>(this Control control, string id) where T : Control
   4:     {
   5:         return (T) control.FindControl(id);
   6:     }
   7: }

So now I can type this:

   1: employeeListView.Find<DropDownList>("regionDropDownList");

Enjoy!

Wednesday, December 15, 2010

VS2010 Tip: Quickly Move Text to another file.

You can quickly move text from one file to another by selecting the text you want to move and drag it onto the tab of the destination file.

Thursday, December 9, 2010

Fixing the Display of Variable Width Select Lists in IE7

I recently helped a client with an ASP.NET website that targeted the IE7 browser. We weren’t doing anything specific that required IE7, but we knew that 99% of the users would be using IE7 as this was the standard installation for the internal users who would be given access to the system.

Several of the pages had select lists in the header of tables that would act as column filters. Unfortunately, IE7 has an incredibly annoying method of rendering select lists. It will shrink the input so that it is contained with its parent element, but when you click the pull-down to expand the selection list, the list does not expand to the width of the select list item. In our case, with narrow columns this resulted in some select lists where the user could only see the first few letters of each option, which is obviously useless.

Read more at Thycotic’s blog.

Follow me on App.net