Related Master Pages, Best DRY Way?

I have two similar master pages, basically they are quite extensive, but the difference depends on using

common content <form id="form1" runat="server" enctype="multipart/form-data"> common content </form> common content 

and another -

 common content <dn:Form id="form1" runat="server"> common content </dn:Form> common content 

I was wondering how I could do this without having to create two master pages and just change the tags of the form ...

The way I currently, although I am doing this, basically has one main page with different content, a second with internal content and two others that have only form tags and a placeholder inside them, and then dynamically select one main page over other.

Is there a better way to do this or is this the right way? thanks.

Update: I'm not sure my current idea is well expressed:

Base.master will have external content, without inheritance.

Normal and Modified.master will only have different form tags, as inherited from Base.Master

Shared.master will have the internal content inherited from Regular.Master, and if it requires a different form control, then it selects another wizard (which has the same ContentPlaceHolderID for FormContent ), dynamically with something like reading from web.config or the like

  protected void Page_PreInit(object sender, EventArgs e) { this.MasterPageFile = "~/App_Shared/RegularWebForm.Master"; this.MasterPageFile = "~/App_Shared/UrlRewritableWebForm.Master"; } 

The goal of this is to be able to use the same homepage in three different applications for the same web domain.

The idea that my solution was suggested is that I have these four main page files in this App_Shared folder, which is referenced via svn: externals from all projects, so I don’t need to repeat the code. The idea would be that I choose whether Shared.Master (which will be the main file of the main page for all three applications) uses the usual form or user control in the current application, and this choice can be made using a parameter in the web. config for the application.

+4
source share
1 answer

In the main page code, you can override OnInit (or OnLoad or in any number of other places) and determine when you need multi-page encryption, and when you do this, call:

 Attributes.Add("enctype", "multipart/form-data"); 

Even better:

Output a boolean property:

 public bool EncodeMe {get;set;}; 

In each form using a master control set

 Master.EncodeMe = true; // or false of course 

then on the main page use bool to determine whether to encode.

0
source

All Articles