Add Text Box From Code behind in HTML
This code-sample includes adding TextBox from code behind. This sample can be used for many purposes. For example, you can create an application of an online exam and an update record based on a question will have better feelings about your application.
Here is the code
- <body>
- <form id="form1" runat="server">
- <asp:PlaceHolder ID="placeHolder" runat="server" />
- <div></div>
- </form>
- </body>
Write C# code in the Page_Load event.
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- HtmlInputText input;
- HtmlTable tbl = new HtmlTable();
- HtmlTableRow row;
- HtmlTableCell cell;
- string HtmlContent = "
- <table>";
- for (int i = 0; i < 4; i++)
- {
-
-
- HtmlContent += "
- <tr>
- <td>" + i + "</td>" + "
- <td>
- <input type='text' class='testoption' name='1' value='optionvalue" + i + "'/>
- </td>
- </td>";
- }
- HtmlContent += "
- </table>";
- placeHolder.Controls.Add(new Literal() { ID = "literal", Text = HtmlContent });
- }
- }
Build the application and you can debug it.