views:

324

answers:

2

how to add the namespace automatically on every new Page, Control added To a WebSite in VS2008?

when i add a new page the code behind looks like this

    public partial class MyNewPage : System.Web.UI.Page
    {

    }

i just want the page wrapped into a namespace as below:

namespace Project.Web
{

      public partial class MyNewPage : System.Web.UI.Page
        {
           protected void Page_Load(object sender, EventArgs e){}
        }
}

this is automatically when you have a website project

maybe its trivial but i haven't find how

+3  A: 

Put the namespace under "Default Namespace" in project properties, and it doesn't need to be in the code files.

Scott Hanselman
Hi Scott,this is not a web site project it doesnt have project properties only property pages. i can see they namespaces are not need, perhaps i just was used to them in my old solutions.Thanks
Oscar Cabrero
A: 

You could try editing the Visual Studio template file for a new page or add you own custom templates. The file you need to edit is "CodeBeside.cs" in the "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\Web\CSharp\1033\WebForm.zip" template archive, at least that's where it is on my system. Just change the class definition to match what you need; something like:

namespace $rootnamespace$
{
    public partial class $classname$ : System.Web.UI.Page
    {
     protected void Page_Load(object sender, EventArgs e)
     {

     }
    }
}

You may need to replace $rootnamespace$ with the namespace you need as I'll unsure how it will be handled in a website project.

bstoney
this is really not an option, since i will need to change i just wanted for a single project, and i dont want to create the template for type of Item
Oscar Cabrero
Fair enough, custom templates can take some time to perfect. Another option would be to record a macro which adds in the namespace in after the new page is added.
bstoney