Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Rename my asp.net web page

Tags:

asp.net

I have a page name with XYZ.aspx

Now I want to change ABC.aspx how should I do it?

When i directly change it from solution explorer it gives me an error.

Can anyone help me on this?

Thank You

Smartdev

like image 839
SmartDev Avatar asked Apr 12 '10 16:04

SmartDev


2 Answers

ASP.NET files are usually composed of 1-3 files total depending on the type of project and the file itself. That being said, there is always the markup *.aspx file, then optionally there will be a code-behind *.aspx.cs file and an additional and also optional designer file *.aspx.designer.cs. If you are renaming the file you will need to update code in various places based on the structure of the file itself.

In the event of more than 1 file making up your ASP.NET page you will want to update the .aspx file's header like so:

<%@Page CodeBehind="XYZ.aspx.cs" Inherits="XYZ" %>

to

<%@Page CodeBehind="ABC.aspx.cs" Inherits="ABC" %>

Then in the code behind file

public partial class XYZ : Page { }

to

public partial class ABC : Page { }

Finally, if there is also a *.designer.cs file you will want to update it as well:

public partial class XYZ : Page { }

to

public partial class ABC : Page { }

That should cover all of the files!

like image 129
Nathan Taylor Avatar answered Nov 15 '22 09:11

Nathan Taylor


To change the name of an aspx file (I'm using vs2012) and associated files single click on filename in solution explorer and single click again to select the name of the file, change the name and enter... vs will rename the code behind file and designer file automatically and change the tags linking them. As nathan above said it does not rename the c# in the code behind to reflect the filename (which would be good practice)... nor importantly does it do a solution wide search for links and more oblique code references to the file. So it's best to do a manual find in files over the entire solution to check and all naming conventions are good.

That should do it

like image 33
VerilyMayhem Avatar answered Nov 15 '22 09:11

VerilyMayhem