Print Style in ASP.NET in IE8 - asp.net

I am trying to link a stylesheet to a masterpage in SharePoint with asp.net. It is a print-only stylesheet. The problem im having is that #media print does not work in IE8.
Can i add a stylesheet in asp.net that only applies to print media?
<SharePoint:CssRegistration ID="CssRegistrationCommon" Name="<% $SPUrl:/Style Library/CSS/common.css %>" After="corev4.css" runat="server"/>
Thanks

You can also specify the media on the link for the stylesheet.
media="print"
make sure you main stylesheet points to something like screen/projector so they don't overlap
<link rel="stylesheet" href="<%= Page.ResolveUrl("~/CSS/mystyles.css") %>" type="text/css" media="screen, projection" />
<link rel="Stylesheet" href="<%= Page.ResolveUrl("~/CSS/print.css") %>" type="text/css" media="print" />

Related

CSS Style sheet not loading in asp.net mvc using Razor

I have used these lines inside head tag
<link href="~/Content/site.css" rel="stylesheet" type="text/css" />
<link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />
Bootstrap seems to work, but site.css is not loading..I even tried
<link href='#Url.Content("~/Content/site.css")' rel="stylesheet" type="text/css" />
I couldn't find any solution. Where am I going wrong?

CSS files loading but CSS not being applied

I have an ASP.NET MVC project using Boostrap 4 and jQuery DataTables. For both tools, the CSS files load but none of the CSS rules are applied. Looking at the network tab of Chrome dev tools, content type is coming over as text/css. Here's the code within the head tag of the main layout page:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
#*<link href="#Url.Content("~/Content/bootstrap.css")" rel="stylesheet" type="text/css" />*#
<link href="#Url.Content("~/Content/Site.css")"rel="stylesheet" type="text/css" />
<link href="#Url.Content("~/Content/pushy.css")" rel="stylesheet" type="text/css" />
<link href="#Url.Content("~/Content/MyStyle.css")" rel="stylesheet" type="text/css" />
<link href="#Url.Content("~/Content/themes/base/jquery-ui.min.css")" rel="stylesheet" type="text/css" />
<link href="#Url.Content("~/Content/font-awesome.min.css")" rel="stylesheet" type="text/css" />
<link href="#Url.Content("~/Content/themes/base/theme.css")" rel="stylesheet" type="text/css" />
<link href="#Url.Content("~/Content/DataTables/css/jquery.dataTables.min.css")" rel="stylesheet" type="text/css" />
#*<link rel="stylesheet" type="text/css" href="#Url.Content("~/Content/DataTables/css/dataTables.bootstrap.min.css")" />*#
<link href="#Url.Content("~/Content/DataTables/css/dataTables.bootstrap4.min.css")" rel="stylesheet" type="text/css" />
I've tried using runat="server" in both the link and head tags, using #Styles.Render instead of a link tag, swapping out the minified file with the full one, href with and without #Url.Content(), and using a file directly from Bootstrap, all with no success (haven't been able to find any other solutions on SO either).
MyStyle.css loads and applies properly, but not the Bootstrap or DataTables CSS. This is driving me nuts trying to figure out the issue - what am I missing?
I'm running .NET 4.6.1 on Visual Studio 2017.
Actually another css file from _Layout.cshtml overwrites the view page css file.removed main.css from Viewpage.cshtml

Why my nested master page loses CSS formatting?

My website structure is as follows
/Style.css
/MasterPage.Master
/Default.aspx
/Member/
member.master
member.aspx
The /MasterPage.Master points to style.css as follows
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
and it works like a charm.
After adding the member.master as a nested master page of MasterPage.Master i noticed that both the VS2010 and the rendered webpage, could not apply the formatting at the child member.master
After some googling i found that i could use the following code
<link rel="stylesheet" href="<%= ResolveUrl("style.css") %>" type="text/css" media="all"/>
The webpage is rendered correctly now, but how can i have the same result in design mode with the visual studio?
As I see, all paths should go as relative paths.
If you have the style sheet as
<link href="~/Style.css" rel="stylesheet" type="text/css" />
the pages should work well. At the same time you need to have master pages referred as:
In your member.master:
MasterPageFile="~/Site.master"
In member.aspx:
MasterPageFile="~/Member/member.master"
Hope this will help you.

ASP.NET MVC inline tags not working with <link href>

Every time I put an inline tag on the link's href attribute it somehow gets auto-encoded. Is this ASP.NET's default behavior? How can I dynamically set the Href attribute using code? This is in MVC btw.
Attempted something like this
<link href="<%: Link.Content.Jquery_css %>" rel="stylesheet" type="text/css" />
which rendered this (nothing changed)
<link href="<%: Link.Content.Jquery_css %>" rel="stylesheet" type="text/css" />
and this
<link href="<%= Link.Content.Jquery_css %> rel="stylesheet" type="text/css" />
which produced this (I couldn't remember the exact numbers, but it seems the bracket-percent-equals was encoded to link format)
<link href="/View/Shared%25Link.Content.Jquery_css%25" %>" rel="stylesheet" type="text/css" />
Link.Content.Jquery_css is a strongly typed string containing the link made using T4MVC.
Add'l info: I used ASP.NET MVC 2, in .NET 4 and testing in Firefox.
I got the same issue in the master page. (It doesn't happen in an individual page.) I found removing "runat=server" from the head tag fixed the problem.
It's getting auto-encoded because of the tag your using (<%: %>). If you don't want the URL to be Encoded, use the following:
<link href="<%= Link.Content.Jquery_css %>" rel="stylesheet" type="text/css" />
Change the ":" to "=" and that remove the auto encoding
Your view is unable to access Link.Content.Jquery_css property. ASP.NET unhelpfully doesn't throw any error.
Move that line inside the body of the page and you will see compilation error.
You could do this:
<head>
<style type="text/css">
#import "<%= ResolveUrl("~/content/styles.css") %>";
#import "<%= ResolveUrl("~/content/print.css") %>" print;
</style>
</head>

Link to resources such as css and javascript files

How can I link to resources such as css and javascript files? My default project is using links like ../../Content/styles.css. How can I do something like ~/content/styles.css?
<link rel="stylesheet" href="<%= Url.Content("~/content/styles.css") %>"
type="text/css" />
<script src="<%= Url.Content("~/content/scripts/file.js") %>"
type="text/javascript"></script>
Leave out the ~. "/Content/styles.css"

Resources