All pastes #2128733 Raw Edit

Unnamed

public text v1 · immutable
#2128733 ·published 2012-03-16 13:14 UTC
rendered paste body
public static Control FindControlByTagId(Control.ControlCollection collection, int tagId)
        {
            foreach (Control ctrl in collection)
            {
                if (ctrl.Tag != null)
                {
                    if (Convert.ToInt32(ctrl.Tag) == tagId)
                    {
                        return ctrl;
                    }
                }

                if (ctrl.HasChildren)
                {
                    object subControl = FindControlByTagId(ctrl.Controls, tagId);
                    if (subControl != null)
                    {
                        return (Control)subControl;
                    }
                }
            }
            return null;
        }