Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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?

Gamer extraordinaire. Programmer wannabe.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...