如何将服务器端控制放入 Literal 中?
我想将服务器端控件放在文字中。是否可以?如果是,怎么办?我知道课程的描述说明了一切:
表示 ASP.NET 中的 HTML 元素、文本和任何其他字符串 不需要服务器处理的页面
I want put a server-side control in a Literal. Is it possible? If yes, how? I know the description of the class says it all:
Represents HTML elements, text, and any other strings in an ASP.NET
page that do not require processing on the server
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想将服务器端代码包装在其他控件中,您可能需要使用面板。正如评论已经指出的,不可能将文字文本视为服务器端控件。
If you want to be wrapping server side code in other controls you probably want to be using Panel. As the comments have already stated, it is impossible to treat literal text as a server side Control.
有趣的是,当我昨天查看一些旧代码时,就出现了这个问题。文字可以做到这一点。我这样做最初是为了通过 Javascript 的 Web 服务调用发出用户控件(哎呀,我知道......这很有趣),但这也适合您的需求。
将文字放在页面上,并将其文本值分配给 RenderUserControlAsString(“用户控件的路径”)。话虽如此,在您的用户控件中,您必须将子控件包装在表单控件中。
我希望这有帮助!
Funny this comes up as I just looked through some of my old code yesterday. Literals can do this. I did this originally to emit user controls through a web service call from Javascript(yikes, I know...it was fun) but this will fit your needs as well.
Throw your literal on the page and assign it's text value to RenderUserControlAsString("Path to your User Control"). With that said, in your user control you must wrap child controls within a form control.
I hope that helps!