This project has moved and is read-only. For the latest updates, please go here.

System.Web.UI.Control Extension Methods

Control.FindControl Method

Searches the current naming container for a server control with the specified id parameter.

Syntax

T FindControl(Control @this,string id)

Parameters

@this
The @this to act on.
id
The identifier for the control to be found.

Type Parameters

T
Generic type parameter.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System.Web.UI;
 using System.Web.UI.WebControls;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_Web_UI_Control_FindControl
     {
         [TestMethod]
         public void FindControl()
         {
             // Type
             var @this = new Control();
             @this.Controls.Add(new Literal {ID = "Fizz"});
 
             // Examples
             var value1 = @this.FindControl<Literal>("Fizz"); // return control as Literal.
             var value2 = @this.FindControl<Literal>("Buzz"); // return null;
         }
     }
 }
                

Control.FindControlRecursive Method

Searches recursively in the container and child container for a server control with the specified id parameter.

Syntax

T FindControlRecursive(Control @this,string id)

Parameters

@this
The @this to act on.
id
The identifier for the control to be found.

Type Parameters

T
Generic type parameter.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System.Web.UI;
 using System.Web.UI.WebControls;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_Web_UI_Control_FindControlRecursive
     {
         [TestMethod]
         public void FindControlRecursive()
         {
             // Type
             var @this = new Control();
             @this.Controls.Add(new Control {ID = "Fizz"});
             @this.Controls[0].Controls.Add(new Literal {ID = "Buzz"});
 
             // Examples
             Control value1 = @this.FindControlRecursive("Fizz"); // return control as Control.
             var value2 = @this.FindControlRecursive<Literal>("Buzz"); // return control as Literal.
             Control value3 = @this.FindControlRecursive("Z"); // return null;
         }
     }
 }
                

Control.FindControlRecursive Method

Searches recursively in the container and child container for a server control with the specified id
parameter.

Syntax

Control FindControlRecursive(Control @this,string id)

Parameters

@this
The @this to act on.
id
The identifier for the control to be found.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System.Web.UI;
 using System.Web.UI.WebControls;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_Web_UI_Control_FindControlRecursive
     {
         [TestMethod]
         public void FindControlRecursive()
         {
             // Type
             var @this = new Control();
             @this.Controls.Add(new Control {ID = "Fizz"});
             @this.Controls[0].Controls.Add(new Literal {ID = "Buzz"});
 
             // Examples
             Control value1 = @this.FindControlRecursive("Fizz"); // return control as Control.
             var value2 = @this.FindControlRecursive<Literal>("Buzz"); // return control as Literal.
             Control value3 = @this.FindControlRecursive("Z"); // return null;
         }
     }
 }
                

Last edited Nov 23, 2013 at 7:57 PM by Jonathan_Magnan, version 1