Click here to Skip to main content
16,017,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to add Textbox control dynamically on the web page using C#.

i have written code as:

TextBox tx1 = new TextBox();
tx1.Text = "Dynamic Textbox";
Page.Controls.Add(tx1);

I am getting error regarding runat attribute.

How can i add runat attribute to the textbox programatically
Posted

Hi Amu,
You need to add your text box inside a PlaceHolder control.
take a Placeholder:
ASP.NET
<asp:placeholder id="plc" runat="server"></asp:placeholder>

And then add your textbox object to PlaceHolder:
C#
TextBox tx1 = new TextBox();
tx1.Text = "Dynamic Textbox";
plc.Controls.Add(tx1);


I hope it will help you.
Good luck.
 
Share this answer
 
v2
Comments
Amu@184 7-Aug-12 2:30am    
Thanks it works
Raje_ 7-Aug-12 2:33am    
Glad to hear that it worked.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900