---
title: Adding custom code to your website
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

The easiest way to insert custom code into a portal engine based website is using standard ASCX user controls. If you are not familiar with Visual Studio development, you can [skip this page](https://docs.kentico.com/k82tutorial/walkthrough-creating-a-new-site-using-the-portal-engine.md).

## Current time example

In this example, we will create a simple user control (ASCX) using Visual Studio and integrate it into the Home page.

1. Open the website project using the **WebSite.sln** or **WebApp.sln** file, which is located in the folder where you installed the website.
2. Create a **Web User Control** and set its name to \*GetTime.ascx.\*You can set the programming language option to either Visual C# or Visual Basic.
3. Drag the following ASP.NET controls onto the page from the toolbox and set their properties:

   - **Button** control:

     - **ID**: Button1
     - **Text**: Get time
   - **Label** control:

     - **ID**: Label1
     - **Text**: \<clear the value>
4. Switch to the **Design** view and double-click the **Show current time** button.
   - The user control's code behind file opens and creates the **Button1\_Click** method.
5. Enter the following code into the **Button1\_Click** method:

   ```csharp

   Label1.Text = DateTime.Now.ToString();

   ```
6. Save the user control's files.

The code ensures that the label displays the current date and time when the button is clicked. You do not need to build the project — user controls are compiled at run time.

## Adding the user control onto the page

1. Log in to the Kentico administration interface and open the **Pages** application.
2. Select the **Home** page and switch to the **Design** tab.
3. Adda **User control** web part to the **Main zone**.
4. Enter the following value into the web part's **User control virtual path** property\*: **\~/GetTime.ascx**\*. The \~ character represents the root of your web application.
5. Click **Save & Close**.

Switch to **Preview** mode to see the user control's output on the page. When you click the **Get time** button, the current date and time appears next to the button.

> **Tip:** **User controls versus web parts**
>
> You can also insert custom code onto portal pages by creating your own web parts. Web parts are very similar to user controls, but with a built-in portal engine configuration interface. We recommend building web parts if you need easily re-usable and configurable user controls.
>
> For more information, see [Developing web parts](https://docs.kentico.com/k82/custom-development/developing-web-parts.md) in the main documentation.
