如何将一个字符串变成一个UserControl
有什么方法/可能性可以用 UserControl 替换字符串吗?
除了 LoadControl 并将其添加到另一个控件(例如页面或占位符)之外。
原因是用户在页面上添加内容并放置类似 {uc:test} 的字符串,我想解析此文本并将 {uc:test} 替换为 UserControl。
换句话说 ; 用户输入将是“bla bla bla {uc:test} bla bla”,当我从数据库检索它时,如何注入用户控件并将其替换为 {uc:test}
谢谢。
Is there any ways/possibilities that I can replace a string with a UserControl?
apart from LoadControl and adding it to another control like page or placeholder.
The reason is that a user add a content on the page and put a string like {uc:test} and I would like to parse this text and replace {uc:test} with a UserControl.
in other words ;
The user input will be "bla bla bla {uc:test} bla bla", when I retrieve it from database how can I inject usercontrol and replace it with {uc:test}
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 LoadControl 方法动态加载用户控件并在回发期间将它们添加到页面。
您可以...将其添加到页面的控件集合:
或者...将其添加到另一个控件的控件集合
如何使用正则表达式获取这样的标签
Try the LoadControl method to dynamically load user controls and add them to your page during postback.
You could... Add it to your page's control collection:
Or... Add it to another control's control collection
How about getting the tags like this using regex
如果您希望尊重所有用户输入,包括它们包含的任何控件引用,请使用ParseControl:
这将创建一个新的
Control
,它将所有文本(“blah blah”)表示为 Literal 子控件,并创建
的新实例作为嵌套子控件。If you want all of the user input to be respected, including any control references they've included, use ParseControl:
This will create a new
Control
which represents all the text ("blah blah") as Literal child controls, as well as create new instances of<uc:test>
as nested child controls.