Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Finding controls using FindControl

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mufasa - 06 Dec 2007 19:58 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.