Custom CodeBehind File?

C

Chris

When I create a new aspx page, VS automatically creates the assocaited
codebehind file also. Is there a way to specifiy what goes in that
codebehind file by default? I mean, if I wanted to see a couple lines
reserved at the top for comments, every time a new codebehind file is
generated, can I do that? How hard is it to do?
 
M

Michael Nemtsev [MVP]

Hello Chris,

Not sure that you can inject into codebehind creation, but is comments the
only thing you need to do?!
What about creating template for your project?

---
WBR,
Michael Nemtsev [Microsoft MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


C> When I create a new aspx page, VS automatically creates the
C> assocaited codebehind file also. Is there a way to specifiy what goes
C> in that codebehind file by default? I mean, if I wanted to see a
C> couple lines reserved at the top for comments, every time a new
C> codebehind file is generated, can I do that? How hard is it to do?
C>
 
G

Gaurav Vaish \(a.k.a. MasterGaurav\)

codebehind file by default? I mean, if I wanted to see a couple lines
reserved at the top for comments, every time a new codebehind file is

Very much.

Go to
<Visual-Studio-Installation-Folder>\Common7\IDE\ItemTemplatesCache\Web\CSharp\1033\WebForm.zip

Update the file CodeBeside.cs
 
C

Chris

Thanks guys for the tips. I took the WebForm.zip and made a copy of
it, and changed the codebeside file the way I wanted it to look. It's
working great, but when I go to add a new item in my project
(ASP.NET), under custom templates, it still says 'Web Form'. Is there
any way to change the name? i.e., 'My Custom WebForm'. I'm guessing
it's somewhere in the TemplateData tag in the vstemplate file, but I'm
not sure where to go from there.
 
C

Cowboy \(Gregory A. Beamer\)

Edit the templates. I have not done this with VS 2008 yet, so they may have
moved the templates (most likely into the user directories), but it was
under the Visual Studio directory (under Program Files) before. You simply
find the correct project and then edit the code behind template, which will
end in .language (.vb for VB and .cs for C#). Look at other templates for
tags to automagically fill in your own FUD.

If this is not enough customization, you can get the SDK and start creating
your own templates and wizards.
 
C

Cowboy \(Gregory A. Beamer\)

After hitting send, I got curious.

It is a bit more complex with Visual Studio 2008 (and I have not yet tested
this). The files are located at:

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\
64-bit
C:\Program Files (x86)\Microsoft Visual Studio
9.0\Common7\IDE\ItemTemplates\

They are organized by language and type. IN this release, all are held in
zip files. If I were doing this, I would back up the current files first and
then edit the files inside the zip and replace the zip on the drive. I doubt
there is a checksum, but if there is, it will fail (thus the backup).

If I get a chance to test, I will repost.
 
C

Cowboy \(Gregory A. Beamer\)

Look at a few of them and you will see what tags are available to have it
automagically mark up the file with file name, class name, etc. I wish I had
a list of them to share, but I don't.


Thanks guys for the tips. I took the WebForm.zip and made a copy of
it, and changed the codebeside file the way I wanted it to look. It's
working great, but when I go to add a new item in my project
(ASP.NET), under custom templates, it still says 'Web Form'. Is there
any way to change the name? i.e., 'My Custom WebForm'. I'm guessing
it's somewhere in the TemplateData tag in the vstemplate file, but I'm
not sure where to go from there.
 
C

Chris

I figured it out. In the vstemplate file, I changed this line:

<Name Package="{afhadfhadgashgjwsaggasgh34}" ID="3062"/>

To this:

<Name Package="{afhadfhadgashgjwsaggasgh34}" ID="3062">My test
template</Name>

And when I go to use it in my project, the name I designated shows
up. Working splendidly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top