WebPart using UserConrtols

on Monday, October 5, 2009

Just Develop your UserControl and then put it in LayOuts/ControlTemplate/YourCompanyfolder and then load it in CreateChildControls method of the webpart as below.


using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls.WebParts;
using System.ComponentModel;
using System.Web.UI;
using UserControls;
public class WebPart2:WebPart
{
[WebBrowsable(true)]
[WebDescription("User Control Path")]
[WebDisplayName("User Control Name")]
[Category("Custom Properties")]
[Personalizable(PersonalizationScope.User)]
public string UserControlPath { get; set; }

[WebBrowsable(true)]
[WebDisplayName("Display All Lists")]
[WebDescription("Display All Lists")]
[Category("Custom Properties")]
[Personalizable(PersonalizationScope.User)]
public string SiteURL { get; set; }


private TestUC control;

protected override void CreateChildControls()
{
TestUC control = (TestUC)Page.LoadControl(UserControlPath);
control.SiteURL = SiteURL;
Controls.Add(control);
}


}

0 comments: