Is it possible to create class libraries that contain UserControls so I can reuse them? If so, how? Is the markup compiled with the .dll? Thanks for any help!
You can compile both UserControl
s and Page
s into class libraries because ultimately, this is what happens after your web site is just in time compiled. The process is a little involved because really UserControl
s and Page
s aren't meant to be used across applications.
From MSDN:
The UserControl gives you the ability to create controls that can be used in multiple places within an application or organization
http://msdn.microsoft.com/en-us/library/system.windows.forms.usercontrol.aspx
The prefered method for controls that are going to be used across applications would be to create custom web server controls.
If you really want to stick with UserControl
s though, the basic process to obtain this functionality is as follows:
UserControl
s.Copy the compiled library from the bin directory and the ascx files as needed from the published site into the new site.
Yes, as point number four states, you do need to copy the ascx files. The markup will be contained in the class library and the ascx will actually be empty. There is no way to avoid this (unless you use custom web server controls) because UserControl
s are added to Page
s through their file names.
All of this is documented in more detail over at MSDN,
http://msdn.microsoft.com/en-us/library/aa479564.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With