ASP.NET Applications
By marygarrison
How to copy an existing aspx page, successfully
Visual Studio 2005 – For all VB.NET Users Developing ASP.NET Applications
When I first began programming in Visual Studio, last summer. I had attempted to copy web pages (.aspx files), that I had already created, in my web software projects.
The reason to create a new web page, from an existing web page, is to save steps, if your software projects have similar pages in the same application. I figured out, the hard way, how to be able to do, what seemed like to me, should be an otherwise, pretty simple task.
Please note the problem with just copying, and renaming, the page file, didn’t surface until I published the project to the web host server, and tried to run my program from the internet. Then my program would crash when the copied page was selected.
As I tried to figure out the error messages, I kept getting, I couldn’t find the solution anywhere. Other programmers just told me to create a new page, rather than copy, and then copy the similar elements, from one page, to another. But this bothered me, and I had to figure out a way to successfully copy an existing page, in order to create a similar new page.
Here are the steps to follow, if you would also like the
ease of being able to copy existing pages, from your web projects, using Visual
Studio. Realize, as with any procedure on the computer, there is more than one
way to do some of the tasks that I detail.
I’m describing the steps I take.
Solution Explorer
Step 1
To Copy/Rename/Use ASPX Pages:
- From the Solution Explorer window (View; Solution Explorer)
Copy It
Next
- Right-click your mouse pointer on the desired [PageName].aspx page
- From the short-cut menu that displays, left-click on the ‘Copy’ option (the menu disappears)
- From the keyboard, press the key combination, ctrl-v
Raname Option
Then...
- Look at the displayed pages in the Solution Explorer window, and you will see a new page titled: Copy of [original page’s name].aspx
- Right-click on the new page in the Solution Explorer window
- Left-click on the option ‘Rename’ from the displayed short-cut menu (the menu disappears)
- Type a new name (you must keep the extension .aspx on the renamed page)
- From the keyboard, press the ‘Enter’ key, to keep new name
Rename It
Source Tab
Almost Done...
- Double-left-click, in rapid succession, on top of the new page from the Solution Explorer window
- The page opens, displaying the source code for the page (If you are not seeing the Source code for the page, since this setting default may be changed, look in the lower left of the page. There is a tab titled ‘Design’ and a tab titled ‘Source’, left-click on the tab titled ‘Source’)
Critical change...
- The first line should look something like this: (I’ve bolded what needs to be changed. Don’t worry about the word-wrapping over more than one line)
<%@ Page Language="VB" MasterPageFile="~/TheNetMaster.master" AutoEventWireup="false"
CodeFile="Example.aspx.vb"
Inherits="Main" title="The NET" %>
2. Change the Inherits=”to the new page’s name, like the following example.
<%@ Page Language="VB" MasterPageFile="~/TheNetMaster.master" AutoEventWireup="false"
CodeFile="Example.aspx.vb"
Inherits="Example" title="The NET"
%>
3. Then save changes, either through the toolbar option, or the file menu
The Code Behind Window
- Now press F7
- The ‘code window’ opens, and should look something like:
Partial Class Main
Inherits System.Web.UI.Page
End Class
- Change
the Partial Class setting on the Code page (Microsoft, the developers of
Visual Studio, call this the ‘Code Behind’ page, to be the same as the
Inherits setting that was changed on the source page. Your change should look something like
this:
Partial Class Example
Inherits System.Web.UI.Page
End Class
You're Done!
The page is now useable, and will not crash, for having copied from an existing page, in order to create the new page. You can proceed to make any other required changes to the page’s code and source sheets, needed for your web program (ASP.NET).
I hope my “How To” document, spares others, from the frustration that I experienced, in figuring out how to create a page, from a copy of an existing page, while developing web programs, using Visual Studio.
Comments
No comments yet.
![]() | Amazon Price: $459.96 List Price: $589.95 |
![]() | Amazon Price: $26.51 List Price: $49.99 |
![]() | Amazon Price: $460.53 List Price: $549.00 |
![]() | Amazon Price: $21.75 List Price: $39.99 |



