Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

hi

 

this is my first post in this forums... hope it get answerd soon..

 

can we load controls dymanic as we do in vb6.

and position them.

 

and is this possible in asp.net

  • Moderators
Posted

Since this was in Windows Forms, here's an example....

 

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim btn As New Button()
       Dim i As Integer

       For i = 1 To 10
           btn = New Button()
           With btn
               AddHandler .Click, AddressOf btnClick
               .Text = "button " & i
               .Location = New Point(0, i * 60)
               .Size = New Size(100, 50)
           End With
           Controls.Add(btn)
       Next
   End Sub

   Private Sub btnClick(ByVal sender As Object, ByVal e As EventArgs)
       MessageBox.Show("You clicked ... " & DirectCast(DirectCast(sender, Button).Text, String))
   End Sub

Visit...Bassic Software
  • Moderators
Posted

For ASP...

'top of page, inside your class...
   Private Panel1 As New System.Web.UI.WebControls.Panel()
   Private PlaceHolder1 As New System.Web.UI.WebControls.PlaceHolder()
   Private button1 As New System.Web.UI.WebControls.Button()
   Private label1 As New System.Web.UI.WebControls.Label()

'inside your Page_Load event...
   Controls.Add(PlaceHolder1)
   PlaceHolder1.Controls.Add(Panel1)
   Panel1.Controls.Add(label1)
   Panel1.Controls.Add(button1)
'then you can format the controls once they are added to the form

Visit...Bassic Software
  • 2 weeks later...
Posted

Thanks, Robby. This is exactly what I was looking for. I'm creating a new app for .NET using an old program concept I had and I needed the ability to add more controls when needed.

 

One question though, is what is a good method to later destroy them if not needed? For example, if the form only needs 5 at one time, then the user adds more by setting option, then decides they only really need 3 now, is there an easy way to identify the ones added to destroy?

mov ax, 13h

int 10h

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...