In server user control, I simply record the number of child controls.
Is there a reason why the counter will be zero if the <%%> tags are used in the body of the control tags?
Here is my extremely simplified control:
public class Script : Control { public override void RenderControl(HtmlTextWriter writer) { writer.Write(this.Controls.Count.ToString()); } }
When only literal data is transmitted, the count is considered equal to 1, as expected:
<my:Script runat="server" ID="script3" > function foo(){} </my:Script>
When transmitting literal data and some calculated data, the counter goes to zero:
<my:Script ID="Script1" runat="server" > function foot(){} <%=String.Empty %> </my:Script>
There is nothing special about String.Empty. Everything that I do here leads to zero.
Interestingly, other Control tags work just fine. Next counter 3:
<my:Script runat="server" ID="Script2"> hi <asp:HyperLink runat="server" NavigateUrl="/" Text="hi" /> </my:Script>
Is there any other way to get the child "content" of a user control? I think there is some way, like it, but I can only check the metadata for System.Web.UI.WebControls.Content - not an implementation.
source share