About Me

My photo
a Dynamic and Energetic guy.....

Wednesday, September 17, 2008

Create a webpart using Visual Studio

This is an old method, but i think this will be useful if someone has very basic knowledge.
User can add a usercontrol & any code can be in your usercontrol

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;
using System.Web.UI;

namespace UCAddSubjectNewsWebpart
{
public class UCAddSubjectNews : WebPart
{
UserControl usercontrol;
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
usercontrol.RenderControl(writer);
}

protected override void CreateChildControls()
{
base.CreateChildControls();
this.Controls.Clear();
usercontrol=(UserControl)this.Page.LoadControl("~/usercontrols/Name_of_user_control.ascx");
this.Controls.Add(usercontrol);
}
}
}

No comments:

My Masters