Mike Ogden pointed out the fact that the DynamicControlsPlaceholder (DCP) does not correctly recreate System.Web.UI.LiteralControl. At first I was very perplexed because I was somehow sure that I successfully tried that before. However, I must have mixed it up with the System.Web.UI.WebControls.Literal which works without problems.
That raises the question why there are two different controls and how they differ. The major difference is that the LiteralControl does not persist the Text property in ViewState, which is why it is recreated emptily by the DCP. The Literal, however, takes a LiteralControl as a child and saves its Text in ViewState:
protected override void AddParsedSubObject(object obj) { if (!(obj is LiteralControl)) { throw new HttpException( HttpRuntime.FormatResourceString("Cannot_Have_Children_Of_Type", "Literal", obj.GetType().Name.ToString())); } this.Text = ((LiteralControl) obj).Text; }
So, if you want to use literal controls with the DynamicControlsPlaceholder make sure that you use Literal instead of LiteralControl.
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
© Copyright 2008, Denis Bauer