views:

52

answers:

2

Hello,

We have some code which is designed to build up a key/value pair of controls on a ASP.NET webforms page and their values. We use the "Controls" collection and recursion to build up this key/value pair.

The only issue is that ascx controls don't appear to come back in the "Controls" collection. Instead we get the controls on the ascx.

Something similar to the following code:

protected override void OnLoad(EventArgs e)
{
    GetControls(this);
}
protected void GetControls(System.Web.UI.Control ctl)
{
    foreach (Control subCtl in ctl.Controls)
    {
        GetControls(subCtl);

        string value;
        if (GetValueFromControl(subCtl, out value))
        {
                _ControlValues.Add(subCtl.ClientID, value);
        }
    }
}

The subCtl is never a ascx control. Is there a way to get a list of the ascx controls on page or better still a different collection that contains both types?

Thanks

Hans

+1  A: 

As far as I know, ASCX controls are included in the Controls collection.

I've made a class inheriting off of System.Web.UI.WebPage that would iterate through all of the controls in this.Controls and it included all of the ASCX classes.

SAGExSDX
+1  A: 

.ascx controls do appear in the controls collection.

Looking at your code, I wonder if this is perhaps an issue with the GetValueFromControl function -- perhaps it's not functioning correctly for .ascx controls, or whatever value you're looking for is not set? Or perhaps the equivalent recursion function in your real code is only adding leaf nodes to _ControlValues, and skipping over nodes with children?

millerjs
cheers think i have it now