Home > DeveloperSection > Forums > creating html div in c#
Manoj Bhatt
Manoj Bhatt

Total Post:154

Posted on    August-29-2014 1:20 AM


 1 Reply(s)
 1029  View(s)
Rate this:

I am using the following code to make an html div in c#

System.Web.UI.HtmlControls.HtmlGenericControl dynDiv =

        new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");

            dynDiv.ID = "dynDivCode";

            dynDiv.Style.Add(HtmlTextWriterStyle.BackgroundColor, "Gray");

            dynDiv.Style.Add(HtmlTextWriterStyle.Height, "20px");

            dynDiv.Style.Add(HtmlTextWriterStyle.Width, "300px");

            dynDiv.InnerHtml = "I was created using Code Behind";


But this does not do a thing, it gives an error at the last line that dynDiv is not a valid argument.

 I want to use div here to simulate cache memory line and placement of words in cache memory

.Please tell me how to do it

Sumit Kesarwani

Total Post:378

Posted on    September-01-2014 12:26 AM

You could just embed the html inside a literal control.

this.Controls.Add(new LiteralControl("<div style='color: gray; height: 20px; width: 300px;'>I was created using Code Behind</div>"));

Don't want to miss updates? Please click the below button!

Follow MindStick