简体   繁体   English

无法将新的文字动态添加到ASP.NET Panel Control

[英]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: 我试图以这种方式将动态控件添加到WebForms控件ASP:Panel中:

1). 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). 2)。 I have already defined Panel , which updates its content and I'm adding new items to it, like this: 我已经定义了Panel ,它会更新其内容,并向其中添加新项目,如下所示:

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

3). 3)。 Literals paragraphBegin && paragraphEnd are adding well, but not the breakLine Literal and I don't understand clearly - why isn't it adding ? Literal literalBegin &&段落末尾添加得很好,但breakLine Literal却没有添加,我不清楚, 为什么不添加

The final problem occurs with the method in CodeBehind: SetSceneEditableUserInfo() 最后的问题出现在CodeBehind中的方法: SetSceneEditableUserInfo()

And the final result does look like: 最终结果看起来像:

在此处输入图片说明

As you see, Literal , which implements <br /> doesn't work at all. 如您所见,实现<br /> Literal根本不起作用。 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. 因此,我也尝试过首先向Label.Controls中添加一些Literals (它是<span> ,我认为它将使<br />保留在其正文中),但也没有成功。

What I'm suppose to do, if I want to fix my issue? 如果要解决我的问题,该怎么办?

尝试

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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