views:

375

answers:

1

I built a deployable master page into a dll and referenced it in multiple ASP.NET Web Applications using a virtual path provider. The problem I'm having is that this really confuses the source view of my aspx pages.

Here is the code inside each of my aspx.cs pages which actually attatches the MasterPage to each content page, but as I said, now, my <asp:Content> tags get really confused and I cant CTRL K + CTRL + D my content pages anymore, it throws validation errors on EVERYTHING. HELP!

protected override void OnPreInit(EventArgs e)
        {
            MasterPageFile = MasterPageVirtualPathProvider.MasterPageFileLocation;
            base.OnPreInit(e);
        }
+1  A: 

To get design time support for shared MP you need to provide markup for VS to work with.

You can do this by copying your MP's markup file in you consuming project, removing the codebehind attribute and delete the codebehind file OR add a linked copy with a blank codebehind.

Now set your content page's masterpage to the stub you just created and you should have design time support.

Your VPP should render from the embedded markup at runtime.

Not optimal but if you want design-time support I think this is the only way.

Sky Sanders
So I should set the MasterPageFile attribute in my content page to say "~/MasterPages/Blank.master" and just add the correct content placeholders to Blank.master? And then when the page actually loads it will overwrite the MasterPageFile attribute to my VPP Master Page on the page init?
chrisjlong
@chrisjlong, ok, let me take another run at this in the answer.
Sky Sanders
@chrisjlong, maybe 'stub' is misleading. The markup needs to be complete. And you can can modify the markup while retaining the logic.
Sky Sanders
Yeah I know that sharing master pages is difficult and its frustrating to no end that ASP.NET doesnt make this easier to achieve (since it seems to be something a lot of enterprise level apps would need). I guess though my problem with your solution is that I currently have the markup in my DLL as well, and this is working fine, so literally the entire master page is GAC'd and easily update/deployable to 50 different IIS Virtual Directories that reference it.So it kinda breaks my current scheme to pull out even just the markup and leave the codebhind in the DLL. Dont want to repeat markup
chrisjlong
@chrisjlong, I just read through your other question and I think I understand what is going on now.. you have a working MP assembly, but design time is killing you. So yeah, follow the directions in the answer to provide design time joy and the VPP will load its own logic and markup(?) from the dll. Can you point me to the resource you used to learn embedding the markup as well?
Sky Sanders
@chrisjlong, r.e. i totally underatand not wanting to deploy markup to projects. But if you want design time support you have no other option.
Sky Sanders
I followed what you said pretty closely except the markup i pointed to in design time is basically just a blank master page with the correct content place holders on it (this way my markup code isnt duplicated and no one accidentaly modifies it thinking they are fixing the master page). As to the resouces I used to learn embedding the markup... trial and error.
chrisjlong
@chrisjlong, glad to hear it worked out. The content pages, in design mode, look as though they have empty masters but load the master properly at runtime? And this gets you where you need to be since now design time isn't freaking out. Do I understand this correctly? I would really be interested in examining an example of your solution. Would you be interested in sharing the solution, gutted of all content of course, just interested in the vpp/embedded markup and consuming site implementation?
Sky Sanders
@chrisjlong - I did have some lingering thoughts after answering this. I am a freak for design time love and typically you do not think about using file links for master pages, but in your situation, as long as you divorced the markup from the class by not using the codebehind attribute (would not affect the viability of the master, just means you would have to open the cs manually instead of view code, i THINK) you could link for design time and at run time your vpp will kick in.
Sky Sanders
@chrisjlon - This way you are referencing a single markup page, get full design time markup and if an update was made in any project it would be to the single master markup, which gets embedded at compile time. I think this would work. What do you think?
Sky Sanders
This is pretty much how I am doing it I will try to gut my solution for you to check it out when I get a chance. We seem to have it pretty stable though, the entire master page is in a single dll that we can deploy at will, and each project that uses it has design time support for its content pages even though the master page does not get loaded until runtime.
chrisjlong