1

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.

1
  • are you creating element from code behind ? Commented Mar 20, 2017 at 10:39

2 Answers 2

2

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);
Sign up to request clarification or add additional context in comments.

4 Comments

can HTML textboxes have runat="server" attributes?
If you create and add HtmlInputText as I did you would not require runat Server. They can have but you have to add them in HTML like <input id="id1" runat="server" />
I cannot. because I am creating it dynamically.
Adding HtmlInputText as shown will do the same as runat server would do, Is anything you think could not be done with this?
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.