tags:

views:

254

answers:

3

So let's say you wanted to make a copy of a Web Form page within a .Net Project.

Is there an easier way than:

  1. Copy Source Page
  2. Page Source Page within project to get new page
  3. Exclude Source Page
  4. Rename code behind class for new page
  5. Add Source Page Back

Sometimes I miss something obvious is there a better way to do this? I know the next question would be "Why are you copying code within a project instead for reusing it?" Let's just say that's a secret;).

+1  A: 

I do this:

  1. Select the original ASPX file in solution explorer
  2. Ctrl+C followed by Ctrl+V (quick copy paste)
  3. Rename new ASPX file (let's say NewFile.aspx)
  4. Rename code-behind class name to NewFile
  5. Rename Inherits attribute of Page directive within HTML to end with 'NewFile'
  6. (Optional) If you moved the page into a different folder, you'll need to update the Namespace references in the HTML's Page directive as well as in the code-behind.
Kon
The only reason I added the extra step of removing is on occasion I've had problems were the references get confused on the rename. Maybe there is something weird I do that I'm not noticing.
wonderchook
strange.. I've never had that issue. :/
Kon
A: 

Can you make that form a User Control, and then insert it as needed? Then you can save yourself the trouble of editing every instance of it that you copy.

John Dunagan
I thought about this, there are instances where I do this. Unfortunately I don't think it will work in this case.
wonderchook
A: 
  1. Create new page via "Add New Item"
  2. Copy original markup (minus Page declaration) and paste into new page
  3. Copy code from original code-behind and paste into the new code-behind
Godless667