Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WebParts & UserControls?

1 view
Skip to first unread message

Mario Schymura

unread,
May 30, 2003, 11:44:47 AM5/30/03
to
Hi Everybody

I've added an UserControl (ascx) to my WebPart solution. How can I render
the UserControl to the WebPart.
I've tried to use the LoadControl method of the WebPart.Page object, but i
recieve an Exception without any Information {}. Where has the User Control
to be stored on the SharePoint Server machine?
I would be very thankfull for some help.

Regards,
Mario Schymura


Enrico Samuel

unread,
Jun 2, 2003, 9:42:37 PM6/2/03
to
Hi Mario,

I tried to encapsulate web user control inside web part and it doesn't
work as well. I upload the ascx using Frontpage 2003 to the root
folder of Sharepoint Portal. Then from within the webpart, I use
LoadControl method that points to the ascx. It throws me an exception.

I guess this is not possible.

Anyone has try it and successful?


Enrico Samuel, MCP(.NET)
WinApp Pty. Ltd.


"Mario Schymura" <MarioS...@freenet.de> wrote in message news:<OOrcFMs...@TK2MSFTNGP12.phx.gbl>...

Jason Mauss

unread,
Jun 3, 2003, 4:02:43 PM6/3/03
to
Have you tried adding the user control to the controls collection
instead? This will add it to the control tree hierarchy and asp.net
should process it automatically.

Jason

enr...@winapp.com.au (Enrico Samuel) wrote in message news:<1b9f34d6.03060...@posting.google.com>...

Enrico Samuel

unread,
Jun 4, 2003, 2:28:17 AM6/4/03
to
Hi Jason,

I hasn't gone that far yet. I am having trouble pointing LoadControl
method to the correct path of the ascx file. Don't know where
Sharepoint stores the file exactly. :(

I already uploaded the ascx to the root folder of Sharepoint, declare
the user control dll as safe control in Sharepoint's web config, and
point LoadControl method to the ascx, but I always get exception when
the program tries to run LoadControl statement.


Any pointers are highly appreciated.


Enrico Samuel, MCP(.NET)
WinApp Pty. Ltd.


jam...@hotmail.com (Jason Mauss) wrote in message news:<a4aed981.03060...@posting.google.com>...

Jason Mauss

unread,
Jun 4, 2003, 5:31:14 AM6/4/03
to
Yeah I'm having trouble myself with Web Parts lately...

have you tried putting the Control assembly (.dll) in the \bin
directory under the web root? e.g. C:\Inetpub\wwwroot\bin\ I think
ASP.NET will look there if the assembly has not been imported to the
GAC and isn't under the application's \bin folder.

Enrico Samuel

unread,
Jun 4, 2003, 8:40:06 PM6/4/03
to
Finally I have been able to encapsulate web user control inside the
webpart.

Here is how I did it:

1. Using IIS, create a virtual directory under Sharepoint portal
website to put the web controls in.

2. Exclude the virtual directory from being managed by Sharepoint
- Go to Administrative Tools - Sharepoint Central Administration
- Select Configure Virtual Server Settings - (your portal) - Define
Managed Paths
- Add the new path to the virtual directory and set to exclude

3. Create a new web project in VS.NET that points to the virtual
directory. Create your web user control (ascx) here.

4. Create another project in VS.NET for the web part and add your web
part here. Add project reference to the web project created earlier.

5. In the webpart code:

Protected WithEvents objUserControl As
UserControlRootNamespace.MyUserControl

Protected Overrides Sub CreateChildControls()

objUserControl =
Me.Page.LoadControl("/virtual_directory/MyUserControl.ascx")
Me.Controls.Add(objUserControl)
End Sub

Protected Overrides Sub RenderWebPart(ByVal output As
System.Web.UI.HtmlTextWriter)
objUserControl.RenderControl(output)
End Sub

6. Inspect the designer part of web user control (the ascx file), and
make sure the Inherits attributes of the Control point to the fully
qualified namespace, eg.

Inherits="UserControlRootNamespace.MyUserControl"

NOT

Inherits="MyUserControl"

7. Edit Sharepoint's web.config and declare the web user control's dll
as safe control


This works in my server. Any questions please forward to me.

0 new messages