views:

48

answers:

3

I have a Master Page that has two different "modes" of behavior: "strict input restrictions" and "relaxed input restrictions". The code for what these two modes mean is completely contained in the Master Page and 95% of the functionality of the Master Page is unaffected by this setting.

Content Page A will always use the "strict input restrictions" mode while Content Page B will always use the "relaxed input restrictions" mode.

I've been setting a property of the Master Page from the Content Page to choose the mode, but this feels kludgy. Is there a better way to handle the situation?

I think it's a design-time decision, but it seems like I'm handling it in a run-time way.

+2  A: 

That's how I handle it as well. Unfortunately, Master Pages are a bit of a kludge to begin with. They don't really follow real rules of inheritance so don't try to force that type of thinking on to them.

Sonny Boy
+1  A: 

From the point of view of the master page, it is a runtime decision, as depending upon which page is loaded at runtime, the functionality of the master page changes. You could force it to be a design time decision by creating two separate master pages, but that leads to duplication of your markup and code, though heavy use of user controls can mitigate that.

However, I've implemented similar functionality from time to time, when it is required. It's simple and it works.

Jason Berkan
+1  A: 

Could you not code this at the page level - or better yet, introduce a base page in the middle? And what exactly do you mean by "strict input restrictions"?

IrishChieftain
It's just some arbitrary thing I made up as an example, but basically some of the pages have a restriction on date ranges while others don't.To complicate matters I also have a shared base page.
Greg
As Sonny says, Master Pages are a kludge - they're not even pages, they're user controls. I always make an attempt to factor my common code away from master pages and into either a base page or a separate control - then reference that. I'd just create a small test project and get something along those lines working first :-)
IrishChieftain
Good idea, I think I'll try that.
Greg