When I create a new page in my ASP.NET application I have This code automatically generated:
<%# Page MasterPageFile="~/Site.master" Language="C#" AutoEventWireup="true" CodeBehind="Rh_Acceuil.aspx.cs" Inherits="PAGODE.RESSHUM.Rh_Acceuil" %>
It's really usefull! But the inherits tag is made with project's directories (the file is in de RESSHUM directory)
but I prefer to delete this part and have this:
...Inherits="PAGODE.Rh_Acceuil ...
But I have to do that manually each time..
So, is it possible to set an option with the aim of Visual Studio don't care about directories when he make this nameSpace?
Thanks for response..
There is a similar thread here:
How to NOT include Visual Studio Project folder names in generated namespaces
Looks like you would need Resharper, which is not free for standard developers.
Another option, although perhaps as tedious, is to add new pages in the main project then move them to the appropriate sub folder. At least then you wouldn't have to change the namespace in the aspx page and the code-behind.
In fact I've found a solution to do that without resharper (I'm sure it's a useful tool but expensive)
So, I just discover Item templates in Visual Studio, magic tool with which you can customize the way Visual studio make the files when you want a new item (.cs, .aspx, ...)
And in the templates you can put some values like $name$ or $itemname$ those values are replaced when file is generated.. (here by the name of windows user, and name of the file created)
I just make a file .aspx with all the things I want and for the namespace I just set
Inherits=$itemname$
and the namespace is just the file name in this case..
Thanks for help!..
Related
I want to alter the default code genaration of MVC CRUD ASP . NET.
Visual Studio.It generates pages of "Edit.cshtml/Insert.cshtml/Delete.cshtml"
I want to translate "Edit" to "Alterar" - "Insert" to "Inserir", and I would like that the razor file to be called "Alterar.cshtml" instead of "Edit.cshtml"
How can I do that?
Is it possible?
Yes, you can.
Based on this excellent blogpost by Scott Hanselman I changed the default template in a few steps. The difference between Scott's approach and mine is that he apparently made it in a way that keeps the global default but gives him a separate generator for each project. Since I didn't get it working immediately, I opted to instead just change the global template.
Go to C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 4\CodeTemplates\AddController (some parts of the URI may vary in your situation
Optionally: grant yourselves write privileges on Controller.tt
Open Controller.tt in an editor of your choice and change what you want to change. Note that these are T4 templates so you have a wide variety of tools to your disposition if you want to do more advanced stuff.
Create a new ASP.NET MVC project
Go to the "Controllers" folder and add a new controller (not an api controller)
You don't have to change anything to get a differently named view: the view, including the file in which it is stored, is generated based on the name of the action method that creates it. If you generate the view from Alterar then the popup window will present you with the name "Alterar" for the file.
I've never used Master Pages before, only completed a couple large MVC 3 projects and a lot of Asp.NET "Web Site" e-mail forms. What I'm trying to do is convert an application in ColdFusion over to ASP.NET. I have 20 separate sub-sites which all pull people's information from a common database. In ColdFusion I simply have each of these 20 pages set one variable and then include a main ColdFusion file which takes that variable and displays the appropriate listing of people.
In ASP.NET, I can't do includes. I'm not using WebForms so #include is out the window. I've read up on using Master Pages but can I use those across projects? I'm visualizing creating a "main" project which fetches the data based on an input variable and then 20 simple, very-lightweight (but completely separate) pages that include/display information from the master project. I do not want to have to create 20 projects for this each of which include a common library, because that would mean if I needed to update something I would have to publish all 10 projects, which is something I'd like to avoid.
Is this possible without doing a Web Forms project and #including .aspx files? The file layout I have now is that the master project is in /sites/masterproject and the sub-sites are like /sites/site1/directory, /sites/site2/directory, so this is why I'm thinking this needs to be separate, hopefully a simple page with an include rather than 20 separate projects.
Try this:
<!-- #include file ="mypage.cshtml " -->
In .aspx page, you can use MasterPageFile attribute in #Page directive to specify master page path.
So, using default project template from VS2008, you would have somehting like this in your pages:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" MasterPageFile="../../masterproject/site.master" %>
(just specify proper relative path, absolute path will probably also do the job)
One of the ways you can create the same effect in .net is by creating and correctly using Asp.Net UserControls. http://msdn.microsoft.com/en-us/library/26db8ysc(v=vs.85).aspx. They are pretty much pieces of HTML code which can also have .Net code which later you can simply drag and drop into your other pages and the result HTML will always be the same, or it could also be dynamic. People use it the same way they use includes in other technologies.
Good luck.
I have a large website that I have to localise. To do that, I make use of UI cultures and .resx files. But the controls on the site do not have the meta:resourcekey value necessary to refer to them in the resource files. I'd like to generate them automatically, using the element IDs as the keys, so that this:
<ext:Window ID="wndLoginWindow" Hidden="true">
</ext:Window>
Becomes this:
<ext:Window ID="wndLoginWindow" Hidden="true" meta:resourcekey="wndLoginWindow">
</ext:Window>
Is there a Visual Studio tool/plugin to do this? Do I have to resort to regex substitution? Or is there another way to localise the website that's not as manual to implement?
Visual Studio 2010 has a Generate Local Resource option under the Tools menu. The cursor may have to be actively in the content area for the menu option to be available. I've been using this to create resource files and it automatically adds the resource key attribute to my controls. It works with Literals and Labels and the like but might not work for more complex controls (my pages are pretty simple so I haven't run up against that).
This question already has answers here:
How do you force Visual Studio to regenerate the .designer files for aspx/ascx files?
(48 answers)
Closed 9 years ago.
I just deleted a designer.cs file from a aspx page.. (Don't ask how I can do that.. You don't really want to know..)
Is it a way to regenerate the file for the aspx page? I was hoping that something like "right-click/ generate designer" exists but it is not the case.. :-(
So thanks if somebody have an idea..
Find another solution to my Question, right-click on the aspx file, then choose "convert to web application" and then, the designer.cs file is regenerated..
It is more easier and quick..
This option is no longer available in VS2013, but you can accomplish the same thing by selecting your project in the Solution Explorer, then going to the Project option on the Menu Bar. Near the bottom you will see the Convert to Web Application option. This will generate designer files for all the *.aspx pages in your project that don't have them, but be aware that this may not be what you want if you have a mix of CodeFile *.aspx pages and CodeBehind files. This will also convert CodeFile pages to CodeBehind files. (Courtesy Joisey Mike)
Open the designer and save (you might have to change something in the markup before being able to save). It should be recreated. Event subscriptions and other settings only kept in the designer won't be possible restore though.
EDIT: Make sure that the designer file exists by creating an empty file with just the partial class definition. Also make sure that it's registered in the project file. Then open the designer or the aspx page and make one small change (insert a space in the aspx) and save it. Now the designer file should be recreated.
Use R-Studio from http://www.r-tt.com and undelete it. Use Source Control in the future.
Part from that, try copying the GUI controls into a new page and copy the content of its Designer page to your deleted one.
If editing and saving your aspx file doesn't work, try the following:
Restart Visual Studio
Ensure there are no errors in your aspx file (e.g. missing <%# Register ... %> tags)
Having ReSharper installed helps with step 2 as it prompts to automatically register missing user controls (but in my case, only after a restart).
This worked for me in Visual Studio 2008.
View in browser should recreate it.
Along with all the other suggestions:
In my case, it was a user control that began missing it's designer file. So, in the ascx, I commented out all the content, leaving only the Assembly,Register, and Import headers. I then rebuilt the solution. With that success, I had new designer code auto generated. I removed the comments and rebuilt again. Everything was back in the place it should be.
Your mileage may vary.
Edit: It should be able to recreate it somehow. However my tip still stands: use source control. Some time in the future, you will delete something vital and can't restore it via any means, and then you will be grateful for having source control.
I have just meticulously followed MS instructions for customising a dynamic data page template for one table. Create the folder CustomPages/MyTable/List.aspx, and copy PageTemplates/List.aspx into that folder, but I now get compiler error because I have duplicated methods in both List.aspx files.
What am I doing wrong?
Just in: I found another, non-MS page that I can't find again now, but he suggested the almost obvious: to change the class name in thej 3 files of my custom list page.
I'm not sure what it says in the instructions, but you'll need to change the namespace in the two codebehind files (List.aspx.cs and List.aspx.designer.cs) and in the "inherits" reference in the .aspx file or yes, you will have duplicate methods (same namespace, same class name, same method name).
You should change the namespace to reflect the path that the custom page is in - this will help ensure it stays unique.