﻿using System;
using Composite.Functions;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class C1Function : Composite.AspNet.UserControlFunction
{
    public override string FunctionDescription
    {
        get 
        { 
            return "A demo function that searches for a control with an ID specified."; 
        }
    }

    protected void  ButtonA_Click(object sender, EventArgs e)
    {
        // Grabbing a label from another control
        Label bLabel = (Label)FindControlRecursive(this .Page, "BLabel");

        bLabel.Text = 
			(bLabel != null ) ? "Control A's text box says "  + TextBoxA.Text : "Control B not found";        
    }    
    
    private  Control FindControlRecursive(Control root, string id)
    {
        if (root.ID == id)
            return root;

        foreach  (Control c in root.Controls)
        {
            Control t = FindControlRecursive(c, id);
            if  (t != null)
                return t;
        }

        return null;
    }
}