Groups | Blog | Home
all groups > asp.net building controls > august 2005 >

asp.net building controls : User Controls Reusability


Clift
8/19/2005 9:07:05 AM
I have created a DHTML menu and wrapped it into a asp.net user control
library. I am able to use this in any project by using <%@ Register
TagPrefix="uc1" TagName="menu" Src="...%>. The Src attribute is the problem.
Can anyone give me any information on how to locate my .ascx control in one
central location on my Web Server and access it ? Currently, I can only copy
it into each project directory and I don't want to have to do this everytime
I change the control.

Clift
8/19/2005 12:31:05 PM
Do you have any good sources that could explain this process ?

[quoted text, click to view]
intrader
8/19/2005 6:12:00 PM
[quoted text, click to view]
By definition the src attribute may refer only to a virtual path.

If you wish to share user controls convert them to custom controls and
compile them to a .dll which you can place in the central bin folder of
intrader
8/19/2005 11:01:21 PM
[quoted text, click to view]
In MSDN there are a few examples.
In a nutshell:
1. Convert your ascx to a class.
2. For controls in your ascx add a protected field with proper control
class.
3. Provide a constructor for the class that allows you to pass the
context. You will be calling this constructor from your Page_Load event
(in your code-behind file) - this way your class now can still do things
like Response.Write. 4. Provide the Render method overrides to render the
controls

4. Compile the class.
5. In your main page make reference to your class via <%@ Import ...%>


intrader
8/19/2005 11:06:49 PM
[quoted text, click to view]
Another approach http://www.codeproject.com/aspnet/ctrlreuse.asp
AddThis Social Bookmark Button