Dim btn As Button = New Button
btn.Text = "Clicke Me"
btn.ID = "btnAdd"
Me.Master.FindControl("MainContent").Controls.Add(btn) ''MainContent --- this the ContentPlaceHolder Id
Control 'ctl02' of type 'Button' must be placed inside a form tag with runat=server.
That means that the button you have to add need to be placed inside a a form tag with runat=server. Thus, you need to add the control and set the css in the code behind as follows:
adnan2211
Member
2 Points
109 Posts
craeting dynamic button asp.net
Dec 02, 2012 10:36 AM|LINK
i want to create adynamic button using c#
i have 2 problems
first of all i dont c the proportie top or left
in order to set the location dynamicaly
second of all the code dont work
i gote these mistake
Control 'ctl02' of type 'Button' must be placed inside a form tag with runat=server.
tnx
adnan
oned_gk
All-Star
31671 Points
6473 Posts
Re: craeting dynamic button asp.net
Dec 02, 2012 10:57 AM|LINK
jack_shivani...
Member
277 Points
72 Posts
Re: craeting dynamic button asp.net
Dec 02, 2012 11:20 AM|LINK
Dim btn As Button = New Button btn.Text = "Clicke Me" btn.ID = "btnAdd" Me.Master.FindControl("MainContent").Controls.Add(btn) ''MainContent --- this the ContentPlaceHolder IdCatherine Sh...
All-Star
23382 Points
2490 Posts
Microsoft
Re: craeting dynamic button asp.net
Dec 04, 2012 09:38 AM|LINK
Hi,
That means that the button you have to add need to be placed inside a a form tag with runat=server. Thus, you need to add the control and set the css in the code behind as follows:
In the .aspx
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> </div> </form> </body> </html>In the .cs
protected void Page_Load(object sender, EventArgs e) { Button button1 = new Button(); button1.ID = "buttonID"; button1.Text = "button1"; button1.Style.Add("position", "absolute"); button1.Style.Add("left", "200px"); button1.Style.Add("top", "200px"); form1.Controls.Add(button1); }Best wishes,
Feedback to us
Develop and promote your apps in Windows Store