I have a MasterPage and a Content Page
My Content Page has a number of controls, - dropdownlist, text boxes, radio buttons.
I want to loop through all the control and if its one of the controls above then i want to obtain the selectedvalue, text etc
I know I can access the control directly by name, but as this is my learning experience on asp.net, I want to be able to go through the Controls collection
I tried
foreach(Controls ctrl in Master.Controls)
{
}
but I wasnt able to get to the controls I needed.
Edit:: I guess i drew the gun a bit too quick as my intellisense kept failing on me. I solved my issue with this in code behind on my content page
protected void btnSearch_Click(object sender, EventArgs e)
{
foreach (Control ctrl in Master.Controls)
{
if (ctrl is HtmlForm)
{
foreach(Control formControl in ctrl.Controls)
{
if (formControl is ContentPlaceHolder)
{
foreach (Control placeHolderControl in formControl.Controls)
{
if (placeHolderControl is DropDownList)
{
string test = "AA";
}
}
}
}
}
}
}
Now to build a recursive routine