Locate controls on a web page using Controls Collection:
Loop through the Controls collection of the container control
The collection is of type ControlColletion, and return type is Control
Code Listing: Controls Collection
public void Button1_Click(object sender, System.EventArgs e)
{
string txtVal = “”;
foreach(Control c in Page.Controls)
{
foreach(Control childc in c.controls)
{
If(childc is TextBox)
{
txtVal += ((TextBox)childc).Text + “,”;
}
}
}
if(txtVal != “”)
{
Label1.Text = txtVal;
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment