James Posted November 27, 2002 Posted November 27, 2002 I am building a web app and learning asp.net as I go along. From what I understand I must declare every control that is on my presentation in my code-behind. My problem is I have many web controls and think it's a big task to declare every control. Is there a quick and easy way that I can declare them in my code-behind? I wanted to use a for loop however, I don't know the best way to use the for loop. Please help. James Quote
wyrd Posted November 27, 2002 Posted November 27, 2002 I don't know ASP.NET so I'm going to give an answer from a VB.NET stand point and hope it's doable in ASP.NET. :) The simplet way is to make an array for the object, then loop through the array.. something like this; '10 controls. Dim c(9) As SomeControl Dim i As Integer 'Loop through all 10. For i = 0 to 9 'Make a new control! c(i) = New SomeControl() Next If the controls aren't the same then you can declare the array as an Object and do seperate for loops for each type of control you'd like to create within the array. You get the idea, right? Quote Gamer extraordinaire. Programmer wannabe.
Moderators Robby Posted November 28, 2002 Moderators Posted November 28, 2002 I don't think that you can declare them with a for/loop, especially if you are going to add event handelers to the controls. I may be wrong though. Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.