I have a page that has a master page. I'm writing generic code to find
multiple controls on the page (I have a number of controls called tbName1,
tbName2, tbName3, ..., tbName20) and rather than doing all the same code for
all 20 fields, I thought I'd write something that loops through all of the
fields 'finding' the control as it goes. But if I do:
TextBox tbNew = (TextBox) this.FindControl("tbName1");
It comes back as null. If I look at the source generated within the browser,
the field is now called something like ctl00$MainPage$tbName2. Is there
anyway to tell the system to fine tbName2 without putting the prefix stuff
on it which I assume could change?
TIA - Jeff.
mohaaron@gmail.com - 06 Dec 2007 20:49 GMT
Jeff,
I'm in the proecess of doing the exact same thing.
Try this.
ContentPlaceHolder masterPageContent =
(ContentPlaceHolder)Page.Master.FindControl("ContentPlaceHolderID");
Control control = (Control)masterPageContent.FindControl(controlId);
if (control is TextBox)
{
TextBox textBox = (TextBox)control;
// Do something with your text box.
}
Aaron
> I have a page that has a master page. I'm writing generic code to find
> multiple controls on the page (I have a number of controls called tbName1,
[quoted text clipped - 10 lines]
>
> TIA - Jeff.