954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Single Page .ascx UserControl Inheritance

Hi,

Im trying to convert my UserControls to be sharable across multiple projects.

I have read up on this, and it seems that I need to have all code in one file (i.e. in the .ascx, rather than codebehind/designer) so I am trying to do this:

<%@ Control Language="C#" AutoEventWireup="true" ClassName="ImageButton" Inherits="Button" %>
<%@ Register src="Button.ascx" tagname="Button" tagprefix="MIKE" %>
<script runat="server">
        protected override void OnInit(EventArgs e)
        {
            this.ImageTag.Src = ImageStartPath + "/" + ImgSrc + "_Up.png";
            base.OnInit(e);
        }
...

the problem is, that despite the "Inherits" attribute on the <%@ Control tag, set to "Button", which is the base class im trying to inherit from, I can't get the base class of my ImageButton class to be Button, it just stays as the basic UserControl, which is a problem, because I am trying to inherit some properties from the base class...

Any ideas?

Thanks,

Mike

mikesowerbutts
Newbie Poster
24 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

If you are wanting a control to inherit from button it sounds more like you're needing to create a custom server control rather than a user control. To do this you'll need to create a new project using ASP.NET Server Control as the project type. If you goole "ASP.NET custom control" or "ASP.NET composite control" you'll find a lot of tutorials/information covering this topic in more detail.

Cherryhomesj
Junior Poster in Training
58 posts since Sep 2011
Reputation Points: 30
Solved Threads: 17
 

Basically a web user control file (.ascx) should be stored in the current web application however you may create a User Control Libraries to share .ascx between web-apps.

links :

1. How to share ASP.NET pages and user controls between applications by using Visual C# .NET

2. Loading web user controls from blob storage in asp.net

3. How to load a web usercontrol from a physical path rather than a virtual path

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

Hi

I have read through those posts and they're really useful, so thanks!

I am still having problems with how to inherit though as none of those links cover anything like that.

Ideas?

Thanks,

Mike

mikesowerbutts
Newbie Poster
24 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

hi, just to clarify, im looking for the equivalent of:

public partial class ImageButton : Button

in a single .ascx page, which i thought would be:

<%@ Control Language="C#" AutoEventWireup="true" ClassName="ImageButton" Inherits="Button" %>

But it doesnt seem to be...

Mike

mikesowerbutts
Newbie Poster
24 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: