views:

826

answers:

3

I have a site a few years old that contains about 30 aspx Web Form pages with code behind. I want to add a common master page to all these with the minimum amount of work.

Essentially, I just need to add everything in the body tags to the Content Placeholder, and preserve the code behind.

Is there a fast way to do this?

+1  A: 

cut and paste works fine - cut out all the old header/footer stuff and paste in the content control tag, and add the masterpage name and you're done

Steven A. Lowe
Yeah, that's what I'm trying to avoid. I'm looking for the top secret "Add MasterPage to this form" function that Microsoft wrote, but didn't document. You know, the hidden secrets THEY don't want you to know.
chris
@chris: for pete's sake, you could have been done by now! make a keyboard macro if you're that lazy ;-)
Steven A. Lowe
+1  A: 

One thing to keep in mind is when you add a master page you are adding a naming container so all of your client id's will change. If you have any static javascript which is tied to your controls be sure to update the id's.

JoshBerke
What I had to change was the name of the form fields that I was interested in. Original was: Request.Form["requestedItem"],New was: Request.Form["ct100$contentplaceholder1$requestedItem"]Which I don't recall having to do on applications that were created new using master pages.
chris
Any content inside of a master page is prefixed based on the control heirarchy. I am guessing but I think fields in the master page would not be in a naming container. One way to handle this is to get the ClientId of the control server side. The ClientId will be close to the name swap out _ for $
JoshBerke
+1  A: 

For each page do the following - Add an attribute to the <@Page > tag named MasterPageFile="Your MasterPage Path" - Add the following tag - Remove html and head tags and their contents except body tag - Remove the body tags BUT KEEP its contetnts - Remove the form tag - Done

Also had to add a <Content> tag.
chris