---
title: "How to abstract a property in ASP.NET pages"  
description: "How to abstract a property in ASP.NET pages"  
author: "Anonymous User"  
published: 2014-12-05  
updated: 2014-12-06  
canonical: https://www.mindstick.com/forum/12751/how-to-abstract-a-property-in-asp-dot-net-pages  
category: "asp.net"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# How to abstract a property in ASP.NET pages

I am using aspx forms. What we do is that we declare [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) like for every form. Code is at the end

So I was [thinking](https://www.mindstick.com/blog/11889/how-to-change-your-thinking-paradigm) that if we could have a [base class](https://www.mindstick.com/blog/116/base-class-initilization) that have all the stuff like this but as the form already inherit the Page class we don't have [multiple inheritance](https://www.mindstick.com/forum/159471/how-does-c-plus-plus-support-multiple-inheritance-and-what-are-potential-issues-associated-with-it) in C# so here can we use [interface](https://www.mindstick.com/articles/12101/interfaces-in-java-extending-interfaces) to achieve this I am new to oops please let me know it is possible or not.

public [partial class](https://www.mindstick.com/forum/155717/define-partial-class-in-mvc) Default2 : System.Web.UI.Page

{

public string ImagePath { get; set; }

}

## Replies

### Reply by Anonymous User

You don't need to inherit from two classes. You need to create a class layer in-between.

First create a class that inherits from Page and add your property:

```
public partial class MyPageBase : System.Web.UI.Page{    public string ImagePath { get; set; }}
```

Then inherit all other classes from your base class. In there you can access everything from Page and MyPageBase:

```
public class MyPage : MyPageBase{    public string TestAccessBaseProp()    {        var foo = base.ImagePath;    }    public string SomeAdditionalProperty { get; set; }}
```

### Reply by Anonymous User

You have two options.

Create a base class

You can create a base class that inherits System.Web.UI.Page and inherit this class in all your pages:

```
public class BasePage : System.Web.UI.Page{    public string ImagePath { get; set; }}
```

And then inherit this class in your pages:

```
public partial class Default2 : BasePage{    ....}
```

Create an interface

You can create an interface like this:

```
public interface Interface1{    string ImagePath { get; set; }}
```

And then inherit this interface on all your pages:

```
public partial class Default2 : System.Web.UI.Page, Interface1{    public string ImagePath { get; set; }}
```

As you can see, the first option (base class) has some advantages over the interface option. You have to define and implement your property only once when using a base class. When using interfaces you have to implement the property on every page too.

This is because an interface is only used to define what properties and function there are on an object, not how they work. While a base class can already implement the properties and functions.


---

Original Source: https://www.mindstick.com/forum/12751/how-to-abstract-a-property-in-asp-dot-net-pages

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
