---
title: "Adding User Controls from code behind"  
description: "Adding User Controls from code behind"  
author: "Anonymous User"  
published: 2014-09-29  
updated: 2014-09-29  
canonical: https://www.mindstick.com/forum/2278/adding-user-controls-from-code-behind  
category: ".net"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Adding User Controls from code behind

I have a [user control](https://www.mindstick.com/forum/294/problem-in-access-the-control-inside-the-user-control)(UserControl1) on my [page](https://www.mindstick.com/articles/13031/why-to-make-a-wikipedia-page) and one [Add](https://www.mindstick.com/forum/12983/add-address-in-textbox-when-page-is-load-and-if-i-search-address-in-textbox-show-in-map-by-javascript) more button.Clicking on Add More Button add the same user control again.When i click on user control first time,it adds [second](https://answers.mindstick.com/qa/41761/how-did-the-second-industrial-revolution-influence-women-s-roles-in-society) User Control,but on second time it doesnot add other.I think the control gets lost. I am adding a control like this on [link](https://www.mindstick.com/articles/23633/link-builder) [button click](https://www.mindstick.com/forum/790/form-gets-submiited-twice-on-button-click):-

```
protected void lnkadd_Click(object sender, EventArgs e){    HtmlTableCell tCell = new HtmlTableCell();    UserControl uc = (UserControl)Page.LoadControl("~/Controls/DirectionalPricingCtrl.ascx");    tCell.Controls.Add(uc);    tablerow.Cells.Add(tCell);}
```

## Replies

### Reply by Sumit Kesarwani

Hi Ashish, \

Your code to add controls programmatically is right. Try doing,

tablerow.Cells.Add(tCell);

instead of adding it to the controls. this looks like a [control](https://www.mindstick.com/blog/197/asp-dot-net-repeater-control) rendering issue.


---

Original Source: https://www.mindstick.com/forum/2278/adding-user-controls-from-code-behind

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
