Monday, July 13, 2009

how to programatically manage look & feel of web part

In the Forum i found one question, i put it at the bottom and also suggestion for it
Question
I would like to know is there any tool or how to programatically manage look & feel of web part? I'm adding asp.net controls to CreateChildControls method but how to manage theit look and desing? How to set up their positions and so forth? Is there any grid or someting what can I use to do that?

suggestion
Personally, I prefer to load a .ascx user control in my web part and manage the look/markup in the .ascx, it is much easier for me. Basically this is using the web part class as a wrapper for the .ascx control, all of the logic/etc could be in the user control. Just make a normal user control (.ascx with code behind) then use code similar to below:
public class ContactInfo : System.Web.UI.WebControls.WebParts.WebPart
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}
protected override void CreateChildControls()
{
base.CreateChildControls();
WebControls.ContactInfo ctrl = (WebControls.ContactInfo)this.Page.LoadControl("~/_controltemplates/Custom/ContactInfo.ascx");
this.Controls.Add(ctrl);
this.ChildControlsCreated = true;
}
}


Source form MSDN :http://social.msdn.microsoft.com/Forums

No comments:

Post a Comment