如何使UserControl使用母版页占位符?

时间:2022-01-23 15:55:20

There's quite weird issue and I wonder if it had ever occurred before. It looks odd that nobody had been caught by it, by Google says so.

有一个非常奇怪的问题,我想知道它是否曾经发生过。谷歌这么说,看起来很奇怪,没有人被它抓住。

that's what we have:

这就是我们所拥有的:

Master page

Masterpage.master

blahblagblag

User control whose page is bound to mentioned-above master page

用户控件,其页面绑定到上面提到的母版页

According design, we need to define from .ascx user control

根据设计,我们需要从.ascx用户控件定义

SomeControl.ascx

 <asp:Content ContentPlaceHolderID="phMaster">  // this will not work, and issue is to make it work

But how to do it, considering that user controls cannot be bound to masterpage?

但是如何做到这一点,考虑到用户控件无法绑定到母版页?

Any ideas?

1 个解决方案

#1


I don't think a UserControl can work in the way you are trying to reference it. You would have to put an intermediary aspx page with the master page set which has a Content control referencing your ContentPlaceholder and includes your user control. You can't directly reference that control by going to SomeControl.ascx you'd have to go to a page in which the control sits.

我不认为UserControl可以按照您尝试引用它的方式工作。您必须将中间aspx页面设置为主页面集,其中内容控件引用您的ContentPlaceholder并包含您的用户控件。您不能通过转到SomeControl.ascx直接引用该控件,您必须转到控件所在的页面。

#1


I don't think a UserControl can work in the way you are trying to reference it. You would have to put an intermediary aspx page with the master page set which has a Content control referencing your ContentPlaceholder and includes your user control. You can't directly reference that control by going to SomeControl.ascx you'd have to go to a page in which the control sits.

我不认为UserControl可以按照您尝试引用它的方式工作。您必须将中间aspx页面设置为主页面集,其中内容控件引用您的ContentPlaceholder并包含您的用户控件。您不能通过转到SomeControl.ascx直接引用该控件,您必须转到控件所在的页面。