Share User Control Across Applications - How?

  • Thread starter Chad A. Beckner
  • Start date
C

Chad A. Beckner

Hey everyone,

Ok. I have a "template and skin" setup on the beginnings of a new portal
site. In this site, there are going to be many applications, which will be
store underneath the "master" site. How can I share the template user
controls with these "sub-applications"?

Example:

Root
|
| -> Per article from Microsoft's website, 825996, I have setup a
virtual directory that points to the "common" folder, named
"intranet_common_folder".
| -> Secure Portal Site Folder (say, intranet)
|
| -> Common (a common place to put all my template controls and
other "app-sharing controls"
|-> Some Class or .ascx file or .asp file, etc
| -> WebApplication1 (uses a .ascx file from Common)
| -> WebApplication2 (uses a .ascx file from Common)

Ideas? I've tried the virtual directory approach, but that doesn't work, I
get "The virtual path
'/intranet_common_folder/themes/06_01_2004/site_theme/site_template.ascx'
maps to another application, which is not allowed.". Since I will not have
access to the GAC, and I don't want to have our Admin have to publish to the
GAC, how can I do this?

Thanks for any and all help!

Chad
 
J

John Saunders

Chad A. Beckner said:
Hey everyone,

Ok. I have a "template and skin" setup on the beginnings of a new portal
site. In this site, there are going to be many applications, which will be
store underneath the "master" site. How can I share the template user
controls with these "sub-applications"?

This can be tricky, as User Controls aren't really meant to work this way.
Microsoft seems to have intended anything sophisticated like this to be done
with Custom Controls.
 
C

Chad A. Beckner

Hey John (hehe, do you live on this newgroup?! hehe)...

Anyways, do you mean, .vb class files? I have those, and those seem to be
working. BUT, they do "reference" the site template file, which is an .ascx
file. Do I need to digitially sign it for it to work? I don't want to put
it into the GAC, that's not an option. Basically, I guess, can you point me
in a direction for custom controls and those that load an .ascx (or
whatever) from a folder that is not part of the current application?

Thanks John!

Chad
 
J

John Saunders

Chad A. Beckner said:
Hey John (hehe, do you live on this newgroup?! hehe)...

No. I spend the rest of my time online looking for work...
Anyways, do you mean, .vb class files? I have those, and those seem to be
working. BUT, they do "reference" the site template file, which is an ..ascx
file. Do I need to digitially sign it for it to work?

No, that's got nothing to do with it.
I don't want to put
it into the GAC, that's not an option. Basically, I guess, can you point me
in a direction for custom controls and those that load an .ascx (or
whatever) from a folder that is not part of the current application?

The issue with user controls is that they were meant to be a simple
mechanism for creating common content. But "simple" includes some
restrictions. The fact that you can't easily share them between sites is one
of those limitations.

I'll give you some references to documentation on custom controls:

ASP.NET Server Control Development Basics
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht
ml/cpconwebformscontroldevelopmentbasics.asp)

Developing a Composite Control
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht
ml/cpcondevelopingcompositecontrols.asp)

Before this scares you away, I'll tell you that it's fairly easy to create a
custom control to duplicate the functionality of a user control. The
"Composite Control" article talks about the sort of control you'll need. For
the most part, all you'll need to do is to override the CreateChildControls
method, instantiate and initialize each of your child controls and add them
to the Controls collection. That way, you don't even need to worry about
rendering the control - the child controls will do that for you:

<%@ Control Language="vb" AutoEventWireup="false" Codebehind="uc.ascx.vb"
Inherits="ns.uc"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<asp:Label runat="server" Text="User:" /><asp:TextBox runat="server"
id="txtUser"/><br>
<asp:Label runat="server" Text="Password:"/><asp:TextBox runat="server"
id="txtPassword"/><br>


translates into:

Protected Overrides Sub CreateChildControls()
Dim lblUser As New Label()
lblUser.Text = "User:"
Controls.Add(lblUser)

Dim txtUser as New TextBox()
txtUser.Id = "txtUser"
Controls.Add(txtUser)

Dim lblPassword as New Label()
lblPassword.Text = "Password:"
Controls.Add(lblPassword)

Dim txtPassword as New TextBox()
txtPassword.Id = "txtPassword"
Controls.Add(txtPassword)

MyBase.CreateChildControls()
End Sub

Not a real big deal.
 

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,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top