Regenerate designer.cs [duplicate] - asp.net

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.

Related

Sharepoint MasterPages/Templates customization

I am pretty new to Sharepoint.
I need to customize some Sharepoint Masterpages (the background color, the font type and a few other css requeriments).
Considering I have available the following files: v4.master, default.master and two more pages which are content pages of default.master, plus the COREv4.css file.
I know I should create a copy of one of those master pages (I am not sure which tho) and customize it changing the CSS linked to it). The following questions come in regards of this:
1) The custom CSS file should be a modified copy of the COREv4.CSS or just another CSS file with the desired styles?
2) How do I create/link the customized CSS file for the modified page via Site Settings?. How/Where should I save the new file?.
3) As for the copy of v4.master, How do I load it to "replace" the original one for the site?.
4) The system is built upon Sharepoint 2010. That ensures that the page to have the modified CSS would be a v4.master copy only?.
Thank you for the insight as always.
**Update**
Hi,
I managed to solve the problem getting a general idea with the pdf manual provided, your suggestions and some extra steps I will describe briefly:
1) To place my custom css file I put it in the folder: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\3082\STYLES
2) I opened the site to be customized with Sharepoint Designer 2010.
3) I clicked on the option Main Pages/Master Pages, and selected the page to be v4.master page, copied and pasted it. Then I renamed it right clicking on it, selecting "Rename" and typed the new name, after doing that I right clicked one more and selected "Set page as main default page".
4) To edit the contents of the page I right clicked once more and selected the option "Edit content in advanced mode", right before the head tag ended I copied and pasted:
<SharePoint:CssRegistration name="customname.css" runat="server" After="core4.css"/>
Note that "customname.css" is my css file. Then I clicked on the floppy disk icon on the upper left side of the screen to save.
5) After doing that I used Chrome HTML/CSS Analyzer, inspecting the original (and now copied) master page to browse on the zones that needed customization in order to identify the class names/ids/element types that managed the styles to be changed. Once identified I only added to them the properties that required change, EG:
//Webparts Alternate Highlighted Rows
div#ctl00_MSO_ContentDiv table.ms-viewlsts tbody
tr.ms-alternatingstrong{ background-color:#F7FAF4 }
table.ms-listviewtable.ms-basictable tbody
tr.ms-alternatingstrong.ms-itmhover{ background-color:#F7FAF4 }
I mostly did this by myself by trial and error with Chrome Analyzer but I also helped the task using the Chart found here (http://sharepointexperience.com/csschart/csschart.html), tho at some point going thru it turned a bit tricky and I decided to do it by myself as I mentioned. In the process I repeatedly added more styles to the custom file and then overwrote it on the server location to refresh the page/pages to see how it was looking, this till the end of the process.
Thanks for your help, I hope this serves as a guide for anyone that needs it. If you have questions let me know.
You can create a new master page from the scratch or modify the existing one.
Please have a look at this link it may help you to get answers of your questions
http://www.rdacorp.com/wp-content/uploads/ASP-NET-Master-Pages-and-SharePoint.pdf
It's not advised to modify files of SharePoint.
Better to create new master page file, specify all CSS and script you want inside and install this with feature.
What version of SharePoint do you have? SharePoint 2010 Server or Foundation? Cause with server version you can brand your master page in a cool way:
see this link
Microsoft has a good introductory article on how you can/should do this.
http://office.microsoft.com/en-us/sharepoint-designer-help/customize-a-master-page-to-brand-your-site-HA102449505.aspx

Removing the byte order mark on asp.net page

I'm really stuck. I'm working on an integration project where I'm creating a html fragment using ASP.NET. This fragment will be included as part of another site. The html fragment is created using a simple ASP.NET page with a minimal code behind file.
Te site that will include this html fragment is running PHP. The developer there is complaining that my code is sending the byte order mark as part of the html fragment and this is making his life difficult.
I'm using Visual Studio 2010 for development. I've saved the relevant aspx and aspx.cs files as UTF-8 without signature. However, this doesn't seem to have made a difference and now I'm pretty much out of ideas. The rest of the site is set to use UTF-8 as standard (defined in web.config).
Where should I be looking to alter the BOM behaviour for my aspx file?
If you save the file in Visual Studio I believe it will keep adding the BOM. You need to use a different editor to remove the marker such as NotePad++.
Actually in the advanced save as dialog in Visual Studio there is also an option to save UTF-8 without signature. Have you tried this?
It's confirmed in this question.
You can also use plain old NotePad to save with a different encoding.
Save As...Encoding DropDown.

Is it possible to modify page's namespace default value?

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!..

Visual Studio 2008 formats asp tags to lowercase

Recently, my Visual Studio 2008(with Resharper 4.5) has started to reformat asp tags into lowercase.
Example:
<asp:Repeater runat="server" id="rp">
becomes
<asp:repeater runat="server" id="rp">
and I can't find a way to make it not do this. I use Ctrl-k Ctrl-d to reformat.
I've tried resetting the Visual Studio settings, turning off Resharper. Nothing seems to bite.
I did delete a huge Reflected something folder in my Documents and Settings folder last week, could this be the reason?
Go to Tools | Options...
Expand: Text Editor - HTML
Select the "Format" node, and see what settings you have for "Capitalization" of "Server tag" and "Server attributes - I think the default is now "Lowercase" - try setting that to "Assmebly definition" instead.
More information on these options can be found here:
Format, HTML, Text Editor, Options Dialog Box
I had the same (or very similar) issue.
I also deleted some (but not all) files in the folder
C:\Documents and Settings[username]\Application Data\Microsoft\VisualStudio\9.0\ReflectedSchemas
The reason I did this is because I'm subject to a frankly daft limit on the size of my (Windows XP) roaming profile :-(
After I did this VS intellisense and document auto-formatting started behaving as if it didn't know what the <asp: tags were and treated all the html as plain html (formatted tag names and attributes in lowercase).
I found this blog post by Tim Vasil which pointed me to the solution.
Here's what I did to fix this:
Deleted all files in C:\Documents
and Settings[username]\Application
Data\Microsoft\VisualStudio\9.0\ReflectedSchemas
Deleted all files in
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary
ASP.NET Files
Deleted the .suo User Option file (the file has the same name as the solution file with .suo in place of .sln)
(Note: VS eventually regenerates the various files in it's own time...)
I found the cause. I put back that 650MB big folder in C:\Documents and Settings\My User Id\Application Data\Microsoft\VisualStudio\9.0 and everything seems to be back to normal.
Thanks for trying to help me!
I'm not sure about a permanent fix, but what you can do is select the troublesome coding then hit CTRL+K followed by CTRL+F, so in order..
CTRL + K, F
This will auto format the coding (and make it the proper case).
If this doesn't work then it might be an auto-format issue/setting

Designer files not nesting correctly, messing up intellisense in Visual Studio

Greetings.
I've got a web site project loaded into Visual Studio 2008. The .designer files for all of my ascx controls are not nested under the control in solution explorer, and when I reference something in that control in the code behind, I don't get intellisense.
I've checked the csproj xml file, and the 'compile' elements appear to be the same as those in my other projects where this is working correctly. An example looks like this:
<Compile Include="Default.aspx.cs">
<DependentUpon>Default.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Default.aspx.designer.cs">
<DependentUpon>Default.aspx</DependentUpon>
</Compile>
I've tried playing with the project file, using the Website\Nest Related Files menu command, and everything else that I can think of. Any ideas?
UPDATE
Note that I'm trying to nest files that should be nested already.
This is a response to my own previous post. Got MS Tech Support to straighten it out. On my .aspx pages changing line one in 2 places solved the issue for me.
In the line in each .aspx file in your project that starts "<%Page Language" change "Codebehind=" to "Codefile=", and in your "Inherits=" property if it's set up as ProjectName.FileName then remove the "ProjectName.".
For example if you had a Project named "TestApp" and a file inside it called "NewFunctionalityTest.aspx" change
Inherits="TestApp.NewFunctionalityTest"
to
Inherits="NewFunctionalityTest"
in the first line.
To nest resx files you
Add Existing Item. Add resource and designer files to the project.
Select all resource files (Not Designer files) that are not nested.
Select Properties and change the Custom Tool to PublicResXFileCodeGenerator
Should work
Made sure both partial files are the same namespace and class name? Might also try to remove them and add both files back at the same time.
I ran across this macro a while back to do exactly what you're looking for. The author even posted a video of how to use it. I have never tried it though, so I can't vouch for it.
I don't know if the OP ever fixed his issue, but something very similar is happening to me. The designer.vb files aren't nesting, Intellisense isn't working, etc... The main difference is that I'm not using ascx, I'm using straight up .aspx pages with .vb codebehinds. It appears as though all the controls placed on the aspx page do not appear to VS as declared when I go to manipulate said controls in the codebehind. I get an error list hundreds deep from code I wrote months ago (having no problems with at the time), most of them saying "Name 'objectname' is not declared" where 'objectname' is a textbox, or dropdown menu from the associated aspx page. To answer Vishal's questions...
Can you share whether this happens everytime you create a new project or is it for a specific project...?
It's happening to one project. I have multiple other applications in VS2008 showing no problems.
Did you try compiling the project?
Yes, when I compile it lists out all the build errors that show up in the ErrorList aborts, and kicks over to the ErrorList.
Does intellisense come back after compiling
No.
A little more information on this project: It's a converted VS 2003 project. These problems did not start immediately after conversion from 2003. The conversion happened months ago and I made numerous revisions to the web app since then. There's currently a version with those revisions on a test server to show off new functionality to the client. This problem only cropped up 3 business days ago when I went in to make a few formatting changes to the aspx page. I never got a chance to make those changes however because as soon as I opened the project I got the error list. This issue is affecting every aspx page I have in the project.
I do not think the nesting is an issue for you, seeing nested files is just a eye candy although depends upon matters...
Not getting intellisense is not really a factor of nesting but rather something to do with the way references are hooked up for your project... Can you share whether this happens everytime you create a new project or is it for a specific project...?
Did you try compiling the project? Does intellisense come back after compiling... Typically for WAP projects if for somereason intellisense does not become available it should come after you compile the project...
Let me know if are still facing this issues...

Resources