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
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
enr...@winapp.com.au (Enrico Samuel) wrote in message news:<1b9f34d6.03060...@posting.google.com>...
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>...
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.
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.