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++)
- {
- //Here we have to update record based for question
- //we can store id in name parameter for choice so we can further update choice for questions
- 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 });
- }
- }


SubashPosted Aug 23, 2016, 12:38 AM
Nice