基于代码隐藏 (VB.net) 动态放置用户控件
我有一个用户控件,它本质上是一个主菜单。
我可以将其硬编码到我的 MasterPage 中,但我不希望这样,我希望能够将其动态地放置在 MasterPage 后面的代码中。
<controls:mainMenu ID='MainMenu1' runat='server' />
所以我想做的是类似的事情
if **condition is true ** _
response.write('<controls:mainMenu ID='MainMenu1' runat='server' />')
当然,我知道这是行不通的,但是我如何根据母版页上代码后面的条件放置控件?
顺便说一句,我使用的是 VB,而不是 C#
I have a user control which is essentially a main menu.
I can place it into my MasterPage hard-coded, but I don't want that, I want to be able to dynamically place it with the code behind of the MasterPage.
<controls:mainMenu ID='MainMenu1' runat='server' />
So what I am looking to do is something like
if **condition is true ** _
response.write('<controls:mainMenu ID='MainMenu1' runat='server' />')
Of course, I know that won't work, but how would I place the control based on a condition in code behind on the master page?
I'm using VB by the way, not C#
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以执行类似的操作 -
您需要向页面添加一个 Panel 或 PlaceHolder 控件来保存您的控件。
You could do something like this -
You'd need to add a Panel or PlaceHolder control to your page to hold your control.