Question

I am trying to inherit a dropdownlist. I don't want to compile it and put into a DLL. I want to reference it from the same project, and that component will be used by two other pages, only.

The code-behind is very basic:

.cs page:

namespace UNS
{
    public partial class UDropDown : DropDownList
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}

.ascx page

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UDropDownList.ascx.cs" Inherits="UNS.UDropDown" %>

I want to give reference to this in another .aspx page by registering it like:

.aspx page

<%@ Register Src="~/UDropDownList.ascx" TagPrefix="UTP" TagName="UTN" %>

The question is, when I want to put it on the page, if I write

<UTP: ...  

I cannot get auto complete options, etc. It doesn't appear.

But I can refer to it within other .cs pages, by simply typing UDropDown.

What's the problem?

Était-ce utile?

La solution

The following solved the problem:

How to use a Subclassed Control on an ASP.NET Page?

I used web-config to register my control.

web.config

<pages theme="UTheme">
  <controls>
    <add tagPrefix="UTP" namespace="UNS" assembly="UNS" />
  </controls>
</pages>

Created a new class, not a partial class:

UDropDownList

namespace UNS
{
    public class UDropDownList : DropDownList
    {
    }
}

On the .aspx page, do refer to it like:

<UTP:UDropDownList runat="server" ID="dd" runat="server"
                ClientIDMode="Static" AutoPostBack="false">
</UTP:UDropDownList>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top