.NET Question
- Taxious
- Rum Guzzler
- Posts: 5056
- Joined: Fri Apr 18, 2003 10:16 am
- Location: Denver, CO
.NET Question
FreeC/Dd/Whoever,
I'm having a hard time finding a good answer via google on this and figured someone here wouldn't mind shedding some light. My understanding is that you can build a .NET web project 2 different ways:
1) Using "CodeFile" where every page has an associated *.cs file that it looks to upon run time.
Example: <%@ Control Language="C#" AutoEventWireup="true" CodeFile="footer.ascx.cs" Inherits="footer" %>
2) Using "Codebehind" where every page has an associated *.cs file AND a *.designer.cs file. The project must be built into a *.dll and then that library is used upon run time.
Example: <%@ Control Language="C#" AutoEventWireup="true" Codebehind="footer.ascx.cs" Inherits="footer" %>
So... what are the designer.cs files actually used for? I'm assuming it helps build out the dll, but I'm curious why "codefile" projects don't require them. It looks like (in most of my designer files at least) that it's just a bunch of variable declaration that could be happening in the .cs file?
I'm having a hard time finding a good answer via google on this and figured someone here wouldn't mind shedding some light. My understanding is that you can build a .NET web project 2 different ways:
1) Using "CodeFile" where every page has an associated *.cs file that it looks to upon run time.
Example: <%@ Control Language="C#" AutoEventWireup="true" CodeFile="footer.ascx.cs" Inherits="footer" %>
2) Using "Codebehind" where every page has an associated *.cs file AND a *.designer.cs file. The project must be built into a *.dll and then that library is used upon run time.
Example: <%@ Control Language="C#" AutoEventWireup="true" Codebehind="footer.ascx.cs" Inherits="footer" %>
So... what are the designer.cs files actually used for? I'm assuming it helps build out the dll, but I'm curious why "codefile" projects don't require them. It looks like (in most of my designer files at least) that it's just a bunch of variable declaration that could be happening in the .cs file?
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
-
- Grand Pontificator
- Posts: 3015
- Joined: Thu Mar 13, 2003 5:35 pm
Re: .NET Question
Ok, I looked it up and deleted my earlier post.
1. First of all, let the IDE handle that stuff so you don't need to be manually screwing around with page directives.
2. The CodeBehind directive is obsolete. Framework 2.0 uses a partial class and framework 1.1 used an inherited class with variable declarations as part of the page object, which was dicey because you could mess with them and confuse the IDE. That's why the IDE puts them into a designer file, so you can't screw up the class.
EDIT Again: If you're seeing those designer files, you're probably doing something wrong because framework 2.0 and later creates a partial class and doesn't need them.
1. First of all, let the IDE handle that stuff so you don't need to be manually screwing around with page directives.
2. The CodeBehind directive is obsolete. Framework 2.0 uses a partial class and framework 1.1 used an inherited class with variable declarations as part of the page object, which was dicey because you could mess with them and confuse the IDE. That's why the IDE puts them into a designer file, so you can't screw up the class.
EDIT Again: If you're seeing those designer files, you're probably doing something wrong because framework 2.0 and later creates a partial class and doesn't need them.
-
- Grand Pontificator
- Posts: 3015
- Joined: Thu Mar 13, 2003 5:35 pm
Re: .NET Question
To expand on my previous post, in the old days of .NET 1.1, let's say your web page had a textbox named TextBox1. The IDE would put the variable declaration of it into your code behind file. That way you could set its properties and call its methods. But you could go into the code and change the variable declaration an it would really mess with the IDE. What's worse, sometimes the IDE would get confused if you for example renamed the control in the properties window. The way that 1.1 handled controls on your web page wasn't very clean.
Now enter framework 2.0 with its partial web page class. Now your code behind file is the portion of the class that you'd need to deal with and the IDE handles the web controls on the page behind the scenes, where you wouldn't want to mess with them and can't fuck them up (and neither can the IDE). If you choose to have the controls explicitly declared (using CodeBehind directive), and I have no idea why you would, then the IDE will declare them in a designer file, which is still better than the way .NET 1.1 did it.
Also, these directives aren't project level like you we're thinking in your post - they're page level and you can change them for every page. So you're not "building the project" X number of ways. It's at the page level. And this is just for web sites. There's lots of other types of projects: windows apps, console apps, windows services, deployment projects, etc. that are all completely different.
And again, seeing that designer file should be a clue that you're handling the page wrong.
Now enter framework 2.0 with its partial web page class. Now your code behind file is the portion of the class that you'd need to deal with and the IDE handles the web controls on the page behind the scenes, where you wouldn't want to mess with them and can't fuck them up (and neither can the IDE). If you choose to have the controls explicitly declared (using CodeBehind directive), and I have no idea why you would, then the IDE will declare them in a designer file, which is still better than the way .NET 1.1 did it.
Also, these directives aren't project level like you we're thinking in your post - they're page level and you can change them for every page. So you're not "building the project" X number of ways. It's at the page level. And this is just for web sites. There's lots of other types of projects: windows apps, console apps, windows services, deployment projects, etc. that are all completely different.
And again, seeing that designer file should be a clue that you're handling the page wrong.
- Taxious
- Rum Guzzler
- Posts: 5056
- Joined: Fri Apr 18, 2003 10:16 am
- Location: Denver, CO
Re: .NET Question
Ahhh okay, so the designer files were basically there as a safeguard to avoid user error? I know a lot of our "newer" sites use codefile instead of codebehind so I'm glad to hear we are progressing and not regressing in that sense. It makes things a lot easier IMO compared to having to compile one giant DLL just for a minor change on one page.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
- Taxious
- Rum Guzzler
- Posts: 5056
- Joined: Fri Apr 18, 2003 10:16 am
- Location: Denver, CO
Re: .NET Question
Good to know for future web projects, thanks for the help! The current project I'm referring to that uses codebehind wasn't set up by me but still uses .NET 2.0, so I was a little confused to see it.Freecare Spiritwise wrote:And again, seeing that designer file should be a clue that you're handling the page wrong.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
-
- Grand Pontificator
- Posts: 3015
- Joined: Thu Mar 13, 2003 5:35 pm
Re: .NET Question
Other than manually dicking around with the page directives, the only way I can think of how you'd get a whole project full of those designer files is if you converted a .NET 1.1 project to 2.0 or later.
And yeah, the designer files split the code behind into a) your code and b) the code generated by the designer that you're not supposed to mess with and if you mess with it will regenerate that code and undo whatever you did. So it's almost like code-behind-behind.
I noticed that one of my web services originally created with VS2005 uses CodeBehind for its .ASMX file and doesn't have a designer file, so I'm not sure of the significance of the directive for web services. A web service wouldn't need/have controls.
And yeah, the designer files split the code behind into a) your code and b) the code generated by the designer that you're not supposed to mess with and if you mess with it will regenerate that code and undo whatever you did. So it's almost like code-behind-behind.
I noticed that one of my web services originally created with VS2005 uses CodeBehind for its .ASMX file and doesn't have a designer file, so I'm not sure of the significance of the directive for web services. A web service wouldn't need/have controls.
-
- Grand Pontificator
- Posts: 3015
- Joined: Thu Mar 13, 2003 5:35 pm
Re: .NET Question
A project converted from 1.1 maybe? If it were my project I'd go in and change that for every page if necessary.Taxious wrote:Good to know for future web projects, thanks for the help! The current project I'm referring to that uses codebehind wasn't set up by me but still uses .NET 2.0, so I was a little confused to see it.Freecare Spiritwise wrote:And again, seeing that designer file should be a clue that you're handling the page wrong.
- Taxious
- Rum Guzzler
- Posts: 5056
- Joined: Fri Apr 18, 2003 10:16 am
- Location: Denver, CO
Re: .NET Question
Mmm probably converted from 1.1 - yeah.Freecare Spiritwise wrote:A project converted from 1.1 maybe? If it were my project I'd go in and change that for every page if necessary.Taxious wrote:Good to know for future web projects, thanks for the help! The current project I'm referring to that uses codebehind wasn't set up by me but still uses .NET 2.0, so I was a little confused to see it.Freecare Spiritwise wrote:And again, seeing that designer file should be a clue that you're handling the page wrong.
LOL I'm pretty sure my boss would kick the shit out of me if I went through and tried to change every page to codefile. We are nearly done with this project/client so it would probably just makes things more complicated at this point.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
-
- Grand Pontificator
- Posts: 3015
- Joined: Thu Mar 13, 2003 5:35 pm
Re: .NET Question
Yeah, I understand the reality if getting shit out the door, but I'll also take every opportunity I can to make something perfect. And once a project goes live it takes on a mind of its own. It's much, much cheaper to change something fundamental before it goes live.
I hate being married to every project I've ever done. Doing everything right the first time give me more time for new project development, which is what I like to do, and makes it easier to pass the baton to someone else.
I hate being married to every project I've ever done. Doing everything right the first time give me more time for new project development, which is what I like to do, and makes it easier to pass the baton to someone else.
- Taxious
- Rum Guzzler
- Posts: 5056
- Joined: Fri Apr 18, 2003 10:16 am
- Location: Denver, CO
Re: .NET Question
One of the main setbacks here (for redoing the entire site) is that this content management system requires you to re-upload any aspx/ascx file changes through the site's admin side before they take effect. So I would have to go through the 50 or so files and change them to 'codefile', then upload them all individually back onto the 3 sites (development, QA, production).


Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
-
- Save a Koala, deport an Australian
- Posts: 17516
- Joined: Thu Jan 02, 2003 3:00 pm
- Location: Straya mate!
- Contact:
Re: .NET Question
You need to automate that deployment. Any huge manual task like that is crazy error prone.
Dd
Dd