Friday, 21 June 2013

Inject Controls on Visual Web Parts in SharePoint 2013

Memo to self:

"When injecting controls from code behind in a Visual Web Part in SharePoint 2013, use the Page Load event, not the CreateChildControls().

Example:

------------------------------------------------------------------------------------------------------------
  protected void Page_Load(object sender, EventArgs e)
        {
       
            this.EnsureChildControls();
            this.Controls.Add(new LiteralControl("<span></span>"));
        }

------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment