Add Text Box From Code behind in HTML

This code-sample includes add TextBox from code behind. This sample can be used for many puroses. For example, you can create an application of online exam and  update record based for question will have better feelings about your application.

Here is the code

  1. <body>  
  2.     <form id="form1" runat="server">  
  3.         <asp:PlaceHolder ID="placeHolder" runat="server" />  
  4.         <div>  
  5.         </div>  
  6.     </form>  
  7. </body>  
Wirte C# code in the Page_Load event.
  1. protected void Page_Load(object sender, EventArgs e)  
  2.         {  
  3.             if (!IsPostBack)  
  4.             {  
  5.                 HtmlInputText input;  
  6.                 HtmlTable tbl = new HtmlTable();  
  7.                 HtmlTableRow row;  
  8.                 HtmlTableCell cell;  
  9.                 string HtmlContent = "<table>";  
  10.                 for (int i = 0; i < 4; i++)  
  11.                 {  
  12.                     //Here we have to update record based  for question  
  13.                     //we can store id in name parameter for choice so we can further update choice for questions  
  14.                     HtmlContent += "<tr><td>" + i + "</td>" + "<td><input type='text' class='testoption' name='1' value='optionvalue" + i + "'/></td></td>";  
  15.                 }  
  16.                 HtmlContent += "</table>";  
  17.                 placeHolder.Controls.Add(new Literal() { ID = "literal", Text = HtmlContent });  
  18.             }  
  19.         }  
Build the application and you can debug it.