With this XML file –
<Instructions>
<Admin>
<Instruction>
Steps must be completed in order.</br>
1. Set dates</br>
2. Import.</br>
3. Generate.</br>
</Instruction>
<Style>
<padding-left value="50px"/>
<padding-right value="0px"/>
</Style>
</Admin>
</Instructions>
And this code –
public void LoadInstructions(String instructionKey) {
XmlNode instLabel = mPropsDoc.SelectSingleNode("ApplicationProperties/Instructions/Admin/Instruction");
XmlNode instStyle = mPropsDoc.SelectSingleNode("ApplicationProperties/Instructions/Admin/Style");
Label ctlInst = new Label();
ctlInst.Text = instLabel.InnerText;
foreach (XmlElement styles in instStyle.ChildNodes) {
ctlInst.Style.Add(styles.Name, styles.Attributes["value"].Value);
}
PageContent.Controls.AddAt(0, ctlInst);
}
where PageContent is a ContentPlaceHolder on my page.
The style gets applied to only the first element and the control is rendered as a span control.
Why isn’t it being rendered as a Label and why is the style only being applied to the first line?
As far as I remember, System.Web.UI.Label element(which I presume you’re using), is always rendered as <span>. To create a <label> – you need System.Web.UI.HtmlGenericControl(“label”).