Posts Tagged ‘control’

ASP.Net & C# Create HTML Controls



It is very easy to create HTML controls before running a Web Page. Just Drag and Drop from ToolBox or write HTML code or ASP code for that Web Page (.aspx). But people think that generating HTML controls during runtime is difficult. But it’s quite easy.

There are many methods of generating controls during runtime.

Here is the one.


First thing is that you need to add a Panel by drag and drop it from the toolbox.


After that you need to write the C# code in Page Load event or button event as follows :


Panel1.Controls.Add(new LiteralControl(“<table><tr>”));

Panel1.Controls.Add(new LiteralControl(“<td colspan=2 align=center    valign=middle >”));

Panel1.Controls.Add(new LiteralControl(“<table><tr><td>”));

Panel1.Controls.Add(new LiteralControl(“<input id=’Text1′ type=’text’ value=’Ganesh Mohan’ />”));

Panel1.Controls.Add(new LiteralControl(“</td><td>”));

Panel1.Controls.Add(new LiteralControl(“<a href=https://ganeshmohan.wordpress.com>”));

Panel1.Controls.Add(new LiteralControl(“Hi This is Ganesh”));

Panel1.Controls.Add(new LiteralControl(“</a>”));

Panel1.Controls.Add(new LiteralControl(“</td></tr></table>”));



That’s it. Its all Done. Its So Simple isn’t it!


Read Full Post »