Try Now
More in this section

Forums / Developing with Sitefinity / Setting Control Properties for UserControls (3.6)

Setting Control Properties for UserControls (3.6)

2 posts, 0 answered
  1. Michael Russell
    Michael Russell avatar
    11 posts
    28 Jan 2009
    23 Feb 2009
    Link to this post
    How can I set a control property in a UserControl via code?  I've been muddling through this without much success.  Here is the code I've got so far that properly adds the control, but does not set the property...

                foreach (CmsWebControl c in pg.Staged.Controls) 
                    if (c.IsAscx && c.TypeName.Equals("~/UserControls/Wiki/WikiPage.ascx", StringComparison.OrdinalIgnoreCase)) 
                        CmsControlProperty prop = c.CreateNewProperty(); 
                        prop.Name = "ParentWiki"
                        prop.Value = parentPage.ToString(); 

  2. Michael
    Michael avatar
    7 posts
    19 Dec 2008
    25 Feb 2009
    Link to this post
    Solution found.  Posting here in case anyone else needs to do this.

    In your .ascx control that is creating the other page with the other .ascx control on it, add a <%@ Reference Control="" %> link to the top of the page.

    In my case...
    <%@ Reference Control="~/UserControls/Wiki/WikiPage.ascx" %>  
    //...and below in code...  
    WikiPage c = Page.LoadControl("~/UserControls/Wiki/WikiPage.ascx"as WikiPage;  
    if (c != null)  
       c.ParentWiki = parentPage;  
    pg.Staged.AddControl("Content", c); 

2 posts, 0 answered