|
-
Apr 6th, 2003, 01:56 AM
#1
Thread Starter
Hyperactive Member
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?
-
Apr 6th, 2003, 07:02 PM
#2
Hyperactive Member
Hi, you need to call the Add method of the Controls collection to add the control to your page
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:
<form id="Form1" method="post" runat="server">
<asp:Panel ID="PnlControls" Runat="server">
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server" Text="Button"></asp:Button>
</asp:Panel>
</form>
Then in the code behind button1_click event try
VB Code:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|