How to Apply Style Sheet to HTML Designer Only? - c#

I am working on a Web application project and although I am an experienced Visual Studio developer almost all of that has been in WinForms, console apps, Services, etc. That is, I have very little experience with using VS to develop web pages (Web Forms, asp.net, etc.), however, I am learning how to apply my previous Web page knowledge to VS.
One thing that has been throwing me for a while is how to apply additional CSS files in development, that should not be used in production (because they are already there). Specifically, I am working on a set of pages (DNN module) that is being deployed into a larger website context.
This all works fine, except the VS Web Page Design Editor is nigh useless because it's WYSIWYG rendering is not even remotely close to what the page looks like on the site. I know why this is happening: the site (and DNN) have their own set of CSS files that are getting applied/added to the page.
I know that I could just add those same style sheets to my web page in development (using <link href=...> tags?), however, then the web page would be deployed referencing these CSS files twice (there's a bunch of them too).
So my question is, is there any easy solution to this? Is there some setting somewhere that I can just say "use these additional CSS files in development or in the Design Editor"? (I hHve tried to google this, etc. but I just find dozens/hundreds of articles about how to add or edit CSS in Visual Studio)
Unfortunately I think that may have mis-explained my need somewhat. The issue really is not a development vs production issues, but rather an IDE vs execution issue. When debugging the code or otherwise running it in development, it is still within the DNN test environment we have setup, so it does have the extra file even here.
This is really about the HTML designer, when i am using it it does not have these extra style sheets, so I cannot see what the work I am doing really looks like. Instead, i have to run it every time I want to see whether any change i make looks like it is supposed to. This gets extremely onerous, especially with how slow DNN is to compile and reload.

Hmm, do you have your web project setup to run on IIS instead of IIS Express?
Something I do is often just work in the project then Save and if needed build. Then browse to the Site on my machines IIS instance (right click file in solution explorer and select browse if using ASP.NET Web forms).
Once I have done that I can refresh my page. I also use #if Debug in my code to bypass user login and etc to make round tripping faster...

Related

How to allow designer to edit master page in ASP.NET Web Application Project?

Currently the webmaster can go into IIS and edit files by using Dreamweaver. The problem came when developers deployed a Web Application Project and the webmaster changed the master page to update the design, but then when developers deployed updates to the WAP it overwrote the master page back to the way it was.
So my question is, what is the best way to let the webmaster/designer edit the master page design in an ASP.NET WAP and keep project files in sync with developer projects?
Currently the webmaster can go into IIS and edit files by using
Dreamweaver
That means webmaster is actually editing the production copy of files. Don't do that. Why would you allow production copy to be modified. Rather, as already suggested by #BenRobinson; have webmaster make changes to the version already present in TFS (considering the face that, production branch is different in TFS than main code branching).
That way, once it's been approved that the modified changes are per requirement then you can copy the changes to production branch and do a full deployment along with other code changes.

How do I create an asp.net web page/site project?

I'm using Visual Studio 2012 Ultimate in Windows 8.
I'm confused as to how to start an asp.net web page web site. Is it via Visual Studio, by selecting File | New Website | ASP.NET Web Site (Razor v2) or (some other selection) or do I need to create the asp.net web page web site from WebMatrix and, if so, do I need to install WebMatrix separately from Visual Studio, or was it installed as a part of Visual Studio?
Searching for the existence of an app named "WebMatrix" in Windows 8 returned nothing...
UPDATE
Mike, I'm a third of the way through your book and I think it's great.
A couple of nights ago I read where you called braces brackets or vice versa and almost said out loud, "This cat must be a Brit!" I then read the frontispiece where that exact fact is declaimed.
Anyway, I was reading "C# 5.0 in a Nuts Hell" today at lunch, and read: (a llittle context: the Albahari boys are here discussing asp.net MVC) "What you lose over Web Forms is a designer. This makes Web Forms still a good choice for web pages with predominantly static content." (bottom of page 194).
This ("predominantly static content") describes the site I'm going to build to a T: most of the content will be static or simple links to other sites. The only non-static content will be pushpins on a Bing Map, but even these could be viewed as static (depending on one's definition of static), as they will really remain the same superset - the user just selects which subset they want to see at any given time.
The "static electricity" voltage of my site depends also on whether you call a PayPal button, a Twitter window, and rotating Ads to be static, too, I reckon.
Anyway, I said all that to say this: In my situation, would Web FORMS be better than Web PAGES? Pardon me if the rest of your book answers that question, but ... I'm not the most patient cat in the world.
WebMatrix is an IDE - not a development framework. The development framework that it was primarily designed to support is known as the ASP.NET Web Pages framework. However, within Visual Studio, it is known as an ASP.NET Web Site (Razor vx) and as you have discovered is accessible via the New Web Site option.
You do not need to install WebMatrix in order to develop these types of applications. However, WebMatrix offers more choice in terms of templates for Web Pages sites and starts up a lot quicker than VS. On the other hand, WebMatrix doesn't include any debugging tools.
WebMatrix is completely separate from Visual Studio and is not installed with it. If you want to install WebMatrix, you can get it here: http://www.microsoft.com/web/webmatrix/
This might not be the answer to the question, but I just started using WebMatrix and it seems much easier and convenient to use mostly because of the various templates available.

MVC3 compiling views is slow

When working on a c# MVC3 app in Visual Studio 2010, I have turned on view compilation by editing my project file and setting the wonderful flag
`<MvcBuildViews>false</MvcBuildViews>`
to true. I love it as it means I can compile my views and catch errors.
The only problem that I have now is that it's not really quick! (I have tried turning it off and then it's back up to full speed.)
It looks like it recompiles every view every time - I have about 50 views at the moment, so ideally it would only compile the pages that have changed since last time. Is this at all possible?
I don't think its possible to compile that way in the same project. You could attempt to pull out the views into a separate project, and set it up that way.
http://www.chrisvandesteeg.nl/2010/11/22/embedding-pre-compiled-razor-views-in-your-dll/
As far as I know, building the views is an all-or-nothing flag.
I recommend turning this option off for development environments, but turning it on for a continuous build system that's pointing at your main development branch. That way you can still get an email if you commit something that breaks a view, without adding a lot of time to each build during development.

Crystal Reports conflicting with css .net

the crystal reports i create from visual studio seem to be conflicting with the website format
This is how the menu should be
This is how it is coming with crystal reports loaded on the program
Any idea why its doing this?
The Crystal Reports viewer renders everything into a control that exists on the page. In order to make it look the way it does they needed to add a virtual directory that you can see referenced if you right click and 'view source' on your webpage.
When you do this, you'll see the supporting directory referenced countless times to access everything from JavaScript files to images and CSS. (aspnet_client\system_web\2_0_50727\crystalreportviewers13 is ONE example of the path you might see, depending on the version of Crystal Reports you are using).
My point here, is that the CSS referenced should fall under this path. The issue created on your site is likely due to an issue that arises from the way the CSS applies itself to the page. Unfortunately CSS, like JavaScript objects, can have conflicts with other elements on the page. They aren't "self contained" by nature.
A GREAT way to see the exact location of the CSS causing issues is to install the Web Developer add-on for FireFox or Internet Explorer. With this installed you can go to the 'CSS' menu and actually view the list of CSS files affecting the site. In fact, you can even disable CSS by location and see how it affects the page LIVE. You can also click on objects in the page and it'll expose details about the CSS applied to the objects. Alternatively or as well, you can install the FireBug add-on. It's got a great UI and can give you other tools for investigating it.
Good luck isolating the CSS. Once you've found it you'll need to either adjust your existing CSS to avoid it, use !Important tags to override their styles, or some combination of mark-up and CSS adjustments. I don't recommend adjusting the Crystal Report Viewer's CSS, it's safer and more maintainable to edit YOUR CSS to avoid the issue.

How to deploy an ASP.NET project so that there is no code in the .aspx files?

I've recently become the maintainer of an ASP.NET web project. In the course of deploying some changes, we noticed that at some point the way the project deploys has changed. The project is a web application project. Currently, when I "Publish" it to my local machine, I can open the various .aspx files and see some code--a little ASP, mostly JavaScript, but the majority of the code seems to be compiled into a .dll.
What we would like is to build and deploy this application so that there is no code in the .aspx files--this is how it used to work, before the previous dev stopped maintaining it. There should be no code in the .aspx files at all, just a reference to the compiled .dll files.
Does anyone know what I'm talking about and how to set it up?
EDIT If it helps, it looks like the older version of the app just had text in the .aspx files that said "This is a marker file generated by the precompilation tool, and should not be deleted!" That is what I'm going for.
If you want to do this for your Website just Pre-compile your project for deployment only. You can check out the exact steps in this MSDN article
This will move all the codebehind files into the .dll and create .aspx.compiled files as pointers to the compiled versions in the .dll. Sounds like thats what was being done before.
The code shouldn't be visible from the client's browser.
Any code that in a code-behind will get compiled to a .dll which the pages in the application would reference. The actual code-behind files shouldn't get published with the .aspx files.
.NET code within the .aspx files shouldn't be visible on the client-side because it has no use on the client-side. It should be executed on the server-side to render HTML output to the client. If the .NET code is visible on the client-side in this case, it means the server isn't executing it and the site is essentially broken.
JavaScript code, of course, needs to be visible on the client-side. There are ways to obfuscate it, but the browser needs to see it in order to execute it. So in this case that code should be developed with the full understanding that it is publicly visible and nothing proprietary or compromising should be included in it.
JavaScript code has to exist on the client side, so that has to be on the server. Inline ASP code? I'd look into rewriting that into .NET.
In order to achieve no code in the .aspx files you need to write all the code in the code behind. You use the asp.net events in the life cycle to perform the generation of client code. For example, dynamically generated HTML and javascript could be generated in the Page_Load and written out as a Response. Any asp.net that you may use needs to be dynamically generated in the code behind with everything else.
You will still push HTML and javascript to the client, but all the code will be in assemblies/dll's except the header info in the aspx pages. I have only done this in the context of a web service ( RESTful) where I pushed out XML to an iPhone for consumption. Doing it for a full website may prove to be quite cumbersome.
It doesn't make sense to do this if the concern is security. Moving the code to an assembly is not much more secure than the aspx page. If the concern is to remain concise, I suggest moving to ASP.NET MVC 3.

Categories

Resources