Reputation: 63
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
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
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