1
votes

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.

2
are you creating element from code behind ? - Arun Chandran C

2 Answers

2
votes

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);
0
votes

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'/>";