Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Foreach Page.Controls vs Javascript 1

Status
Not open for further replies.

sodakotahusker

Programmer
Mar 15, 2001
601
I have a search form - which allows users to save their search criteria. If they select one of the saved choices, it will read a database table which contains the name of the page element and the value(s) which go into that element. To complicate this scenario, some of the the elements of combo boxes which allow multiple selections. I can't figure out the best way to do this - especially with the combo boxes. Can I loop through my dataset and have an inner loop which loops through the page controls to find the right one - and make the assignment in the code behind? Or must I look through the dataset and generate dynamic javascript to populate the elements. My boss said no response.write should be used (is this realistic?) so the first solution is the best. However I have been unable to example my list of controls. Page.Controls.Count = 3 whereas I have over 20 server side controls. When I look at the id 2 of them are null and one is the form element. So I am not understanding how the Page.Controls collection is set up.
I need to get this resolved soon. My whole project is due in 3 weeks and this is holding up the rest of the work. Thanks!!!!!!
 
I think you'll find that the controls are nested and that only 3 are directly owned by your page. If the ID of the control is null it generally means that it's an unnamed HTML control.

You will need to drill down through the Controls collection of each control to get a full list of all the controls on the page and this is best done using a recursive subroutine that lists the controls owned by each control it finds.

However if all you want to do is get a reference to a specific control use the FindControl method instead which will do all this for you.



Bob Boffin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top