Results 1 to 2 of 2

Thread: Dynamicly creat a button

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    313

    Dynamicly creat a button

    Ok I set up a basic asp .net project created a page etc, and I added a button to the page, and in the button1_click function i added this

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim S As New Button
            S.Height = Button1.Height()
            S.Width = Button1.Width()
            S.Visible = True
            S.Text = "Test this text"
    
            S.Enabled() = True
        End Sub
    and it did't have the effect i was looking for. I was hoping it would let me dynamicly place a button on the webpage...but nope did't work. can anyone help?

  2. #2
    Hyperactive Member MarkusJ_NZ's Avatar
    Join Date
    Jun 2001
    Posts
    375
    Hi, you need to call the Add method of the Controls collection to add the control to your page

    VB Code:
    1. Controls.Add(S)

    For a button you might have to be specifc about adding the button within the <form> tags. One way of doing this is to create a panel and then add the button to the panels controls..

    VB Code:
    1. <form id="Form1" method="post" runat="server">
    2.             <asp:Panel ID="PnlControls" Runat="server">
    3.                 <asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server" Text="Button"></asp:Button>
    4.             </asp:Panel>
    5.         </form>

    Then in the code behind button1_click event try

    VB Code:
    1. PnlControls.Controls.Add(S)

    HTH
    Cheers
    MarkusJ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width