mostlylucid

RSS Feed Moved to Feedburner May 14

Ramping this thing up for a big change...working on a translation piece between a (heavily modified) BlogEngine.net and the current platform SubText...new feed is here: Rss. Planning to spend the weekend whipping this thing into shape...

Dumb little recursive, generic FindControl method... May 14

Doing some app building and I needed to use FindControl to manipulate a control in the OnItemCreated event in a Repeater...well, to save a bit of typing I came up with this extension method:

 

namespace Presentation

{

    public static class ControlHelper

    {

        public static T FindControl<T>(this System.Web.UI.Control root, string controlId, bool recursive) where T: System.Web.UI.Control

        {

            if(root.Controls!=null && root.Controls.Count>0 && root.FindControl(controlId) != null)

            {

                return root.FindControl(controlId) as T;

            }

            else if(recursive)

            {

                return FindControl<T>(root, controlId, recursive);

            }

            return null;

        }

    }

}

 

Pretty simple but it lets me do the following :

       var link = e.Row.FindControl<HyperLink>("MenuLink", true);

        if(link!=null) link.NavigateUrl="http://www.mostlylucid.net";

Not a HUGE time-saver but it just makes my code a bit tidier...