Finding controls thru iteration in asp.net 2.0

This example shows how to find control from a page which is inside a master page.

public void FindControls(ControlCollection ctlCollection)
{
foreach (Control ctl in ctlCollection)
{
if (ctl.ID == "TextBox")
{
//... some code here
}

}
}



and add the following code in your page (which is inside master page).
ContentPlaceHolder cph = (ContentPlaceHolder)this.Form.FindControl("ContentPlaceHolder1");

findControls(cph.Controls);

Comments

Popular posts from this blog

Fetching Address book AKA Contact information from Device using Xamarin.Forms

Custom Attributes in MVC

Partial view and AJAX Form with MVC3 Razor