RE: find control question
- From: WebBuilder451 <WebBuilder451@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 4 Aug 2008 09:28:05 -0700
a lot of work for a simple task. But i'll try it!
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)
kes
"Yankee Imperialist Dog" wrote:
total bummer here with this i, know! My solution is total over kill here, but.
it works
ok, use generics to return a list of controls.
i use this in a name space, but you could just use it for a simple
/// <summary>
/// returns a list of the given controls
/// </summary>
/// <param name="root"></param>
/// <param name="typ"></param>
/// <param name="ControlList"></param>
/// <returns></returns>
public static List<Control> GetAListOfControls(Control root, Type
typ, List<Control> ControlList)
{
foreach (Control t in root.Controls)
{
if (t.GetType() == typ)
ControlList.Add(t);
if (t.Controls.Count > 0)
{
ControlList = GetAListOfControls(t, typ, ControlList);
}
}
return ControlList;
}
then call it thus for the texh boxes:
List<Control> ctrls = new List<Control>();
ctrls = AdminPageHelper.GetAListOfControls(cph, typeof(TextBox), ctls);
from there you got the list loop or use as you see fit.
--
"WebBuilder451" wrote:
i have a master page and aseries of controls labeled fn1, fn2, fn3 , ...
i want ot loop and use find control but i'm finding them.
i'm using the following w/o luck
ContentPlaceHolder cph =
(ContentPlaceHolder)Page.Master.FindControl("ContentPlaceHolder1");
for (int i = 0; i < 7; i++)
{
TextBox tbF = (TextBox)cph.FindControl("tbFN" + i.ToString());
TextBox tbL = (TextBox)cph.FindControl("tbLN" + i.ToString());
........
}
they come up null
where are the controls located??
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)
kes
- Follow-Ups:
- RE: find control question
- From: bruce barker
- RE: find control question
- References:
- find control question
- From: WebBuilder451
- RE: find control question
- From: Yankee Imperialist Dog
- find control question
- Prev by Date: RE: find control question
- Next by Date: Re: find control question
- Previous by thread: RE: find control question
- Next by thread: RE: find control question
- Index(es):
Relevant Pages
|