 |
BOOK: Beginning ASP.NET 4.5 : in C# and VB
 | This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

April 27th, 2013, 09:49 AM
|
|
Friend of Wrox
|
|
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
|
|
What happened to the code behind file?
One thing I have noticed is that sometimes I don't like to mess up a good file that comes from the downloaded source code so I like to use a "save as" copy feature of that good file. So what I will do, is "a save as" of the file and save that file under a different name. For instance I will save Genres.aspx as Genres1.aspx and when I do that I notice that Visual Studio will not generate a .cs file in for the Genres1.aspx file when I do save as of the Genres.aspx. It will instead refer to the Genres.cs file for the code behind file for the Genres1.aspx file. I know this sounds crazy but that is what I have been running into. Have you ever seen this happen? Why wont it put a .cs file in Visual Studio when I do a "save file as" for files like Genres.aspx?
So if I do save as of "Genres.aspx" as Genres1.aspx, I notice that there is no .cs file for Genres1.aspx in visual studio. This is crazy! How can I do a "save as" file and still get a .cs file for the new saved as file?
For me this is a very big issue that I would really like to understand and get a handle on.
|
|

April 27th, 2013, 09:53 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
It doesn't create one because the one you're saving has a reference to an existing .cs file on disk that it can use.
Simply copy and paste, then rename the file in the Solution Explorer fixes that issue.
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

April 27th, 2013, 10:00 AM
|
|
Friend of Wrox
|
|
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
|
|
Quote:
Originally Posted by Imar
It doesn't create one because the one you're saving has a reference to an existing .cs file on disk that it can use.
Simply copy and paste, then rename the file in the Solution Explorer fixes that issue.
Imar
|
What if I want to use a new or different entity datasource in that newly created file that you say I can create by copy and pasting into a new file? If I make changes to it on the new file that I just created by copy and pasting, will it effect the entity datasource on the other files as well? Because both files will have an entity datasorce with the ID of EntityDatsource1 will they not? Can you get around this issue by simply going to the property pages and renaming the entity datasource for that newly created page that was copy and pasted into? Or... Do you have to build a new entity datasource for that new page as well?
Last edited by vbboyd; April 27th, 2013 at 10:02 AM..
Reason: More info
|
|

April 27th, 2013, 10:02 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I am not saying you should copy *into* a new file, I am saying you should copy the entire file.
>> will it effect the entity datasource on the other files as well?
Why would it? They are just separate files that have no connection to each other....
Imar
|
|

April 27th, 2013, 10:07 AM
|
|
Friend of Wrox
|
|
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
|
|
Okay let me get this straight.
You are saying that I should create a new file as Genres1.aspx, by creating a webpage the standard way in Visual Studio then go to the Genres.aspx file go to the markup section copy all of that, then go to my Genres1.aspx file delete everything there and paste the code from the markup section from Genres.aspx into Genres1.aspx? Is that correct? Is that way to do it rather than do a "save as"?
|
|

April 27th, 2013, 10:11 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
No, I am not saying that at all. Not sure how you think I did. Again, I am saying you should copy the file, not its contents. In Solution Explorer click the file you want to copy, press Ctrl+C to copy and then Ctrl+V to paste. Then Visual Studio will create the new file for you with the correct code behind. All you then need to do is update the Inherits attribute in Markup and the class name in Code Behind as otherwise you'll have to pages with the same class name.
Imar
|
|

April 27th, 2013, 10:23 AM
|
|
Friend of Wrox
|
|
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
|
|
Quote:
Originally Posted by Imar
No, I am not saying that at all. Not sure how you think I did. Again, I am saying you should copy the file, not its contents. In Solution Explorer click the file you want to copy, press Ctrl+C to copy and then Ctrl+V to paste. Then Visual Studio will create the new file for you with the correct code behind. All you then need to do is update the Inherits attribute in Markup and the class name in Code Behind as otherwise you'll have to pages with the same class name.
Imar
|
Okay so then you go to the Inherits attribute of markup section and make sure that you are pointing to the Genres1.cs file and not the Genres.cs? Correct? As far as the class name is concerned, I am not quite sure what you are talking about. Taking a real world example using Genre.aspx what would you have to change in the class name of Genres1.cs so that you won't have two pages with the same class name?
|
|

April 27th, 2013, 10:28 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
Okay so then you go to the Inherits attribute of markup section and make sure that you are pointing to the Genres1.cs file and not the Genres.cs? Correct?
|
No, not correct. The inherits attribute refers to a class name, not to a file name. The filename is fixed for you automatically. The Inherits attribute should be changed from Genres to Genres1.
Quote:
|
Taking a real world example using Genre.aspx what would you have to change in the class name of Genres1.cs so that you won't have two pages with the same class name?
|
The class name ;-)
E.g.:
Change this:
Code:
public partial class Genres : System.Web.UI.Page
to this:
Code:
public partial class Genres1 : System.Web.UI.Page
Can you please not quote the entire message when replying? That clutters up the thread and doesn't add any value as the original post is directly above the quote.
Imar
|
|

April 27th, 2013, 10:33 AM
|
|
Friend of Wrox
|
|
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
|
|
example
Okay so I fired up Visual Studio 2012 and did a Control C and Control V on Genres.aspx and created a Genres2A.aspx. Here is the top of markup section for Genres2A.aspx:
<%@ Page Title="Planet Wrox - Management - Genres" Language="C#" MasterPageFile="~/MasterPages/Management.master" AutoEventWireup="true" CodeFile="Genres2A.aspx.cs" Inherits="Management_Genres" %>
Do I have to change the Inherits "Management_Genres" in this markup section?
This is what I get in the code behind file for Genres2A.cs
Code:
public partial class Management_Genres : System.Web.UI.Page
Last edited by vbboyd; April 27th, 2013 at 10:36 AM..
Reason: More info
|
|

April 27th, 2013, 10:40 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Yes; you need to change the Inherits attribute as well as the class nam ein the code behind (which is what the Inherits attribute is pointing to). Isn't that obvious by now from the last 7 posts in this thread?
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|
 |
|