By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,731 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,731 IT Pros & Developers. It's quick & easy.

User Controls and Custom Controls

P: n/a
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?

Nov 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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.
"Dag" <no****@yahoo.com> wrote in message
news:uy**************@tk2msftngp13.phx.gbl...
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?

Nov 18 '05 #2

P: n/a
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...ositecontrolvs
usercontrol.asp?frame=true

#Recommendations for Web User Controls vs. Web Custom Controls
http://msdn.microsoft.com/library/en...rcontrolsvscus
tomwebcontrols.asp?frame=true

#Developing ASP.NET Server Controls
http://msdn.microsoft.com/library/en...lopingwebforms
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

Nov 18 '05 #3

P: n/a
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.

"Dag" <no****@yahoo.com> wrote in message
news:uy**************@tk2msftngp13.phx.gbl...
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?

Nov 18 '05 #4

P: n/a
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

"Dag" <no****@yahoo.com> wrote in message
news:uy**************@tk2msftngp13.phx.gbl...
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?

Nov 18 '05 #5

P: n/a
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
"Dag" <no****@yahoo.com> wrote in message
news:uy**************@tk2msftngp13.phx.gbl...
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?

Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.