EnzoZow
EnzoZow

Reputation: 63

Creating Dynamic Elements inside Div C# ASP.NET

I want to create dynamic elements inside my div on c# asp.net. I need asp:TextBox instead of HTML textbox. This code works:

create.InnerHtml = "<input type='text' name='name' value='first Text'/>";

while this does not:

create.InnerHtml = "<asp:TextBox runat=\"server\"></asp:TextBox>";

Problem is I need runat="server". How to create asp:TextBox dynamically inside div? or HTML Textbox has attr of runat="server"? Thank you.

Upvotes: 1

Views: 2546

Answers (2)

EnzoZow
EnzoZow

Reputation: 63

I tested if HTML TextBox can have runat="server" attribute, it does! This code works.

create.InnerHtml = "<input type='text' name='name' runat=\"server\" value='first Text'/>";

Upvotes: 0

Adil
Adil

Reputation: 148180

You can create HtmlInputText control with type text and add it in div Controls collection.

HtmlInputText text1 = new HtmlInputText("text");
text1.Name = "name";
text1.Value = "first Text";
create.Controls.Add(text1);

Upvotes: 2

Related Questions