Logo 
Search:

MOSS Forum

Ask Question   UnAnswered
Home » Forum » MOSS       RSS Feeds

User Controls on Page Layout Templates?

  Asked By: Palak    Date: Nov 19    Category: MOSS    Views: 1949

I have created a custom user control (.ascx file) and want to use it
in a MOSS 2007 Page Layout. The question is, how do I get the user
control on the page layout template? If I create a new page layout in
SharePoint Designer all I can drag on the page are the controls that
come with Designer or is there somehow to get my custom control to
show up in the SharePoint Designer tool pane? Can this be done? If
so, how?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Yvonne Rodriquez     Answered On: Nov 19

Use the .ascx control  in a custom  web part.

First, copy the .ascx file  to “12
Hive”\template\controltemplates\.

In your web part project create a new class. Here's
SOME sample code so your web part can reference the
.ascx control:


public class SOVR :
System.Web.UI.WebControls.WebParts.WebPart
{
// Member variables
protected DTCControls2007.SOVR UserSOVR;

protected string UserControlPath =
@"/_controltemplates/";
protected string UserControlFileName =
@"SOVR.ascx";


protected override void CreateChildControls()
{
UserSOVR =
(DTCControls2007.SOVR)this.Page.LoadControl(UserControlPath
+ UserControlFileName);
this.Controls.Add(UserSOVR);
// Get the data for the grid.
string strOrg =
ConfigurationManager.AppSettings["Organization"].ToString();
UserSOVR.Organization = strOrg;
UserSOVR.RetrieveByOrgName();
}

protected override void
RenderContents(HtmlTextWriter writer)
{
this.EnsureChildControls();
UserSOVR.RenderControl(writer);
}

 
Didn't find what you were looking for? Find more on User Controls on Page Layout Templates? Or get search suggestion and latest updates.




Tagged: