---
title: "creating html div in c#"  
description: "creating html div in c#"  
author: "Manoj Bhatt"  
published: 2014-08-29  
updated: 2014-09-01  
canonical: https://www.mindstick.com/forum/2206/creating-html-div-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# creating html div in c#

I am using the following [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) to make an [html](https://www.mindstick.com/articles/1530/design-a-simple-stylish-calculator-using-html-css-and-javascript) 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";            this.Controls.Add(dynDiv);
```

But this does not do a thing, it gives an [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) at the last line that dynDiv is not a valid argument.

I want to use div here to simulate [cache memory](https://www.mindstick.com/blog/304052/explain-what-is-cache-memory-and-why-it-s-needed-when-ram-exists) line and [placement](https://answers.mindstick.com/qa/111373/what-are-the-benefits-of-taking-advanced-placement-ap-courses) of words in cache memory

.Please tell me how to do it

## Replies

### Reply by Sumit Kesarwani

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>"));


---

Original Source: https://www.mindstick.com/forum/2206/creating-html-div-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
