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";

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?



Recommended Answers

All 5 Replies

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.


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.




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...


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.