开发者

Sanity check: Master Page, Content Page and ASCX dependencies

I'd like someone to give what we're doing a glance-over and tell me whether we're going about it an odd way.

What I have:

  • We have a .master (Master Page), .aspx (Content Page) and an .ascx (User Control).
  • The User Control should appear on all pages, so we have placed it on the Master Page
  • The User Control should be initialised differently based on the Content Page it appears on. So, the Content Page has the resposibility of raising an event on the User Control, passing in some arguments, which init开发者_开发百科ialises the control.

Questions:

In my mind, this removes any dependency between the User Control and either the Content Page or Master Page. Am I correct?

Is calling an event on the User Control the easiest way to pass arguments in and initialise the control accordingly?

Happy to clarify any further points, Thanks.


I would say that's OK, but I would like to seek a clarification: how does the user control subscribe to the event of the content page?

Alternatively, you could also consider creating an interface for the master page:

public interface IMyMaster
{
  UserControlType Control { get; }
}

After applying this interface to the master, the interface can return a direct reference to the control. The content page can then do:

if (this.Page.Master is IMyMaster) {
   ((IMyMaster)this.Page.Master).Control.Initialize();
}

HTH.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜