views:

28

answers:

1

I have a Masterfile that has a header control with a button, and the ContentPlaceHolder which would be another page with multiple text boxes.

When I press the button in the header, I need to iterate through all the text boxes and grab their text, how exactly would I do this using C#?

+2  A: 

Check the ContentPlaceHolder for null and if that succeeds, loop through all of the placeholder's controls, grabbing the text from all the TextBoxes. Alternatively, you could use the ContentPlaceHolder's FindControl method.

Nick
Note that with MasterPages, the FindControl method needs to be recursive, because the page hierarchy changes:http://www.west-wind.com/Weblog/posts/5127.aspx
Yoav
Also it would be safe to first check if the control is a TextBox before grabbing the text if iterating.
Diago