- Open STSDEV to create a new project with web part template as snapshot.

- Add a User Control in Project.
- Create directory structure in project as snapshot.

- Change the CustomWebPart1.cs file as following snippet.
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace UCWebPartSl
{
public class CustomWebPart1 : WebPart
{
UserControl userControl;
protected override void CreateChildControls()
{
//Label lblHello = new Label();
//lblHello.Text = "Hello";
//Controls.Add(lblHello);
base.CreateChildControls();
userControl =(UserControl)Page.LoadControl(@"/_controltemplates/WebUCOne.ascx");
this.Controls.Add(userControl);
}
protected override void Render(HtmlTextWriter writer)
{
//base.Render(writer);
userControl.RenderControl(writer);
}
}
} - Change the "Inherits" in WebUCOne.ascx file as following snippet. This assembly can be fetch by Reflector tool.

- Build on "DebugDeploy" mode.
- Activate the web part feature in Site Collection Features management page.
- Add web part to any page as snapshot.
Showing posts with label STSDEV UserControl WebPart. Show all posts
Showing posts with label STSDEV UserControl WebPart. Show all posts
Friday, September 12, 2008
Use User Control in Web Part (Deploy by STSDEV)
Subscribe to:
Posts (Atom)