插入一个
以编程方式标记 (VB.NET)
我正在尝试动态地将结果添加到此显示中,我只想在标签后面放置一个中断标记以开始将信息放在下一行上。 由于某种原因,使用文字对我不起作用。 有没有更好的方法来做到这一点,或者我应该只使用表格?
Dim break As LiteralControl
break = New LiteralControl("<br />")
divListenerInfo.Controls.Add(break)
这是我尝试使用的代码的一部分。
Let me clarify what I said:
它不起作用,因为换行符没有显示在网页上。 编译正常,代码没有任何问题。 只是由于某些奇怪的原因它没有出现在 html 中。
I'm trying to dynamically add results to this display and I simply want to put a break tag after a label to start putting information on the next line. For some reason, Using a literal isn't working for me. Is there a better way to do this or should I just use tables?
Dim break As LiteralControl
break = New LiteralControl("<br />")
divListenerInfo.Controls.Add(break)
That's part of the code that I'm attempting to use.
Let me clarify what I said:
It's not working as in the line break isn't showing up on the webpage. It's compiling fine and there is nothing wrong with the code. It just doesn't show up in the html for some odd reason.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
使用的正确控件是
HtmlGenericControl
。您可以使用
HtmlGenericControl
呈现您想要的任何 HTML 元素,只需将元素的标签名称作为单个参数传递给构造函数即可。The proper control to use is the
HtmlGenericControl
.You can use the
HtmlGenericControl
to render any HTML element you wish, simply pass the element's tag name as a single argument to the constructor.为什么不直接使用另一个标签,或者将
附加到之前的 label.txt 中?Why not just use another label, or append the
<br>
to the previous label.txt?如果添加的
是容器 div 中的最后一个元素,则看不到任何差异。
你可以尝试:
查看中断。
但我认为您应该首先在该 Literal 中添加一个虚拟文本,然后在您的页面中搜索它(如果已添加)。 因为你的代码看起来不错。
If the added
is the last element in the container div, you can not see any difference.
you can try :
to see the break.
But I think you should first add a dummy text into this Literal and search for it in your page if it's added. because your code looks fine.
我知道这正在恢复旧帖子,但我没有看到任何明确的答案,我终于为自己的应用程序找到了答案。 希望它对其他人有帮助!
在我的应用程序中,我尝试创建一次控件,然后在需要的地方再次添加它。 每个父控件只能创建一次该控件。
每次需要时都需要创建一个新控件!
所以这个:
而不是这个
I know this is reviving an old post but I didn't see any clear answer and I finally figured it out for my own application. Hope it helps someone else!
In my application I tried to create the control once and add it again wherever I needed it. The control would only be created once per parent.
You need to create a new control every time you need it!
So this:
Instead of this
我不确定 Break 是否也是 vb.net 中的保留字,所以尝试
或
I'm not sure if break is a reserve word also in vb.net so try
or
我会尝试使用调试器单步执行代码以确保该行被命中,并三次检查
divListenerInfo
是正确的控件。I would try stepping through the code with a debugger to make sure the line gets hit, also triple-check that
divListenerInfo
is the right control.我认为您正在使用面板或占位符。
vb.net 或 C# .net 语法:
I think you are using a panel or placeholder.
vb.net or C# .net syntax: