Controls Collection
-
Dear sirs: I have an ASP.NET Web Form that uses a Master Page. On it, are several Web Controls (i.e. text-boxes, GridViews, etc.) When I use a simple code-snippet like the following: foreach (Control ctl in this.Controls) { Response.Write(ctl.ID); } ... there is one control listed with an ID of "null..." However, I can, of course get the name of any control on the page with "this." How can I iterate through the controls collection of this Web Form? Thanks, R. Hyland
-
Dear sirs: I have an ASP.NET Web Form that uses a Master Page. On it, are several Web Controls (i.e. text-boxes, GridViews, etc.) When I use a simple code-snippet like the following: foreach (Control ctl in this.Controls) { Response.Write(ctl.ID); } ... there is one control listed with an ID of "null..." However, I can, of course get the name of any control on the page with "this." How can I iterate through the controls collection of this Web Form? Thanks, R. Hyland
-
Dear sirs: I have an ASP.NET Web Form that uses a Master Page. On it, are several Web Controls (i.e. text-boxes, GridViews, etc.) When I use a simple code-snippet like the following: foreach (Control ctl in this.Controls) { Response.Write(ctl.ID); } ... there is one control listed with an ID of "null..." However, I can, of course get the name of any control on the page with "this." How can I iterate through the controls collection of this Web Form? Thanks, R. Hyland
Use the following code to obtain the control containing all of your forms controls. Me.FindControl("ctl00").FindControl("contentMaster")) where "contentMaster" is referenced from your asp:content control located at the top of your aspx's source view page. < ... form's html ... Now you have a reference to the control containing all of the controls residing on the page. Michael
I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious. Vince Lombardi (1913-1970)
-
Use the following code to obtain the control containing all of your forms controls. Me.FindControl("ctl00").FindControl("contentMaster")) where "contentMaster" is referenced from your asp:content control located at the top of your aspx's source view page. < ... form's html ... Now you have a reference to the control containing all of the controls residing on the page. Michael
I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious. Vince Lombardi (1913-1970)
Thank you so much, your answer was spot-on! R. H.