简体   繁体   中英

Can't dynamically add new literal to ASP.NET Panel Control

I'm trying to add dynamically controls to my WebForms control ASP:Panel in such way:

1). First of all, I'm defining some Literals in such way:

Literal paragraphBegin = new Literal();
paragraphBegin.Text = "<p>";
Literal paragraphEnd = new Literal();
paragraphEnd.Text = "</p>";
Literal breakLine = new Literal();
breakLine.Text = "<br />";

2). I have already defined Panel , which updates its content and I'm adding new items to it, like this:

this.contentViewWebdata.Controls.Add(labelUserGuid);
this.contentViewWebdata.Controls.Add(editableUserGuid);
this.contentViewWebdata.Controls.Add(breakLine);

3). Literals paragraphBegin && paragraphEnd are adding well, but not the breakLine Literal and I don't understand clearly - why isn't it adding ?

The final problem occurs with the method in CodeBehind: SetSceneEditableUserInfo()

And the final result does look like:

在此处输入图片说明

As you see, Literal , which implements <br /> doesn't work at all. So, I also have tried to add some Literals firstly to the .Controls of Label (which is <span> , and which I thought will keep <br /> in its body), but also no success.

What I'm suppose to do, if I want to fix my issue?

尝试

this.contentViewWebdata.Controls.Add(Page.ParseControl("br"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM