---
title: "Set the Enabled Property of a UserControl From CodeBehind"  
description: "Set the Enabled Property of a UserControl From CodeBehind"  
author: "Takeshi Okada"  
published: 2014-12-03  
updated: 2014-12-04  
canonical: https://www.mindstick.com/forum/12739/set-the-enabled-property-of-a-usercontrol-from-codebehind  
category: "asp.net"  
tags: ["custom controls"]  
reading_time: 1 minute  

---

# Set the Enabled Property of a UserControl From CodeBehind

It's been a while since I worked on WebForms so I need a refresher when working on an old site.

I have a [userControl](https://www.mindstick.com/forum/1929/bind-datatable-to-textbox-usercontrol) on the [page](https://www.mindstick.com/articles/13031/why-to-make-a-wikipedia-page) that I need to programatically set the enabled state

<%@ [Register](https://www.mindstick.com/blog/220/registering-client-script-in-asp-dot-net) Src="CalandarControl.ascx" TagName="CalandarControl" TagPrefix="uc" %>

I have this at the [C# code](https://www.mindstick.com/forum/403/how-to-export-data-in-excel-file-from-sql-server-using-c-sharp-code) but Enabled is not available here. What am I [missing](https://answers.mindstick.com/qa/52138/international-missing-children-s-day-2019-was-observed-on)?

```
if (c is UserControl){    var x = c.GetType();    if (x.Name == "calendarcontrol_ascx")    {        ((UserControl)c).Enabled = true;    }}
```

Thanks

## Replies

### Reply by Anonymous User

You should have something on the [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii)-front that places the control on the page, like:

```
<uc:CalendarControl ID="dtePrepaymentExpiresDate" FieldName="Prepayment expires
date" runat="server" Enabled="false" />
```

Then in the code behind, you can set this custom property as follows:

dtePrepaymentExpiresDate.Enabled = true;

If you really need to do it in the loop, then you need to cast c as the CalendarControl and not UserControl because CalendarControl has the property Enabled while a normal UserControl does not.

((CalandarControl)c).Enabled = true;


---

Original Source: https://www.mindstick.com/forum/12739/set-the-enabled-property-of-a-usercontrol-from-codebehind

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
