1

I am using asp.net 4, vs 2010.

I have a WebSite project, with some paged (apsx) and WebServices (asmx).

I am trying to use a custom UserControl that I included in my project.

The WebControl/UserControl is a plain c# class, with no aspx/ascx/asmx. This class is configured as follows:

public class DropDownMenu : UserControl

Meaning it extends System.Web.UI.UserControl, And it Overrides a bunch of UserControls methods such as OnPreRender, OnLoad etc.

This file compiles OK, But I didn't succeed in using it in an aspx file.

I tried the following:

  <%@ Register TagPrefix="My" TagName="DropDownMenu"  
Src="DropDownMenu.cs"%>

But this dosent work. I recieve a runtime error:

The file 'src' is not a valid here because it doesn't expose a type.

Iv'e also tried

<%@ Register Assembly="DropDownMenu" Namespace="MyNameSpace" TagPrefix="My" %>

and I recieved a run time error

Could not load file or assembly 'DropDownMenu' or one of its dependencies. The system cannot find the file specified.

Does anyone knows how I can use my class as an asp tag/control? I just want to use the following in an aspx page:

< My:DropDownMenu >

1 Answer 1

5

Registration:

<%@ Register TagPrefix="My" Assembly="AssemblyName" NameSpace="NameSpace"%>

Here Assembly and NameSpace contain name of assembly and namespace where control's class is defined, neither of them is the name of the control itself. Note that assembly name does not include file extension.

Usage:

<My:DropDownMenu ...>
Sign up to request clarification or add additional context in comments.

5 Comments

I tried this ive wrote that above <%@ Register Assembly="DropDownMenu" Namespace="MyNameSpace" TagPrefix="My" %>
@meyou, Is DropDownMenu the name of the assembly where the control is defined?
@meyou, what is the structure of your solution? If all your code is situated within one web project, then assembly will most likely has the same name as the project itself.
I managed to make this work , as you said. but I can only use DropDownMenu, althhough I have in the same file many classes. Why is that?
@meyou, only classes representing controls (inherited from Control class, I believe) will be available for you in markup. Usage is the same: <My:ControlName ...>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.