User Controls and Custom Controls

D

Dag

Hi all,

I have a project where we use lots of user controls. We would like to move
them to private assemblied custom controls but from what I see this can't be
done because the .ascx file must be in the main project as a file...in other
words, it doesn't look like you can add a reference to a custom created
control and leverage an .asxc within it.

Is this correct?
 
A

avnrao

if you want to use the user controls in more projects, moving them to a
separate assembly would make sense. but i dont think you can have .ascx
separately.
if all your projects follow a particular folder structure, you can place
these ascx files in a folder and access the relative path from different
projects.

Av.
 
S

Steven Cheng[MSFT]

Hi Dag,

From your description, you used to use some ASP.NET UserControls in your
web applicatoin and currently want to rebuild them as ASP.NET Custom Server
control so as to embed them into assemblies. And you're wondering on how to
deal with the ascx file of the UserControl when moving to Custom
ServerControl, yes?

As for this problem, I think if you want to rebuild these control as Custom
SErver Control , the ascx file for UserControl is no longer used. Because
ServerControl is rather different from the UserControl which will need us
to manually construct it's Control hierarchy and Render out the "Html"
output via code. The UserControl's ascx file is actually a source template
which will be parsed at runtime to help generate the UserControl's actual
class , just like the Asp.net page's dynamic compiled. They're different
from each other. Here are some reference on both of them in MSDN:

#Composite Control vs. User Control
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcompositecontrolvs
usercontrol.asp?frame=true

#Recommendations for Web User Controls vs. Web Custom Controls
http://msdn.microsoft.com/library/en-us/vbcon/html/vbconwebusercontrolsvscus
tomwebcontrols.asp?frame=true

#Developing ASP.NET Server Controls
http://msdn.microsoft.com/library/en-us/cpguide/html/cpcondevelopingwebforms
controls.asp?frame=true

Hope helps. Thanks.



Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
K

Kevin Spencer

Convert them to Server Controls, which don't use a Template file.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
B

Bruno Sirianni

Create a new project for a generic .DLL.
Copy all your .ascx in this project. Add reference and all you need for
build.
Create a PostBuild event for :
- Copy all .ascx in WebApplication
- Copy .dll file in WebApplication\bin
You can have some problem in design (you are not in a webproject) and for
add new item (for ASCX there isn't the wizard outside the webappl!)

In WebApplication add a reference to the project (without copy local!)
In code behind you now can have intellisense and all you need.
The code in .aspx file for add the usercontrols you must write yourself, but
it's not difficult


Enjoy.
Brun
 
D

David Jessee

Bad New's...they have to be Custom Controls
Good News...its not that hard

Probably the easiest thing to do would be to change the base class to Panel.
Then on the Control's OnInit Event, instantiate all of the controls which
the designer created for you ( the Protected Shared Members) and add them
into your base clas's control collection. You'll probably end up adding a
number of additional GenericControl instances to your class as well because
those are what you'll have to use to encapsulate any html in the designer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top