473,786 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CSS Styles in MasterPage

HEEELP!!!!
I have a big problem :)))))

How to use url in CSS stylesheet file that is linked into MasterPage.

The tilda '~' (as shortcut to the root of the webserver) is not working, and
my MasterPage is used by pages not only in root but in other subfolders.

I have this in My MasterPage

<div
onmouseover="th is.style.backgr oundImage='url( images/design/topnav01.gif)'"
/>

if I request default.aspx that is based on MasterPage (both pages are in the
root), this <div> is working well,
But in case I request another page that is located in a subfolder of my
webserver and use MasterPage in the root too, this div is not working.

I tried use the '~' character as shortcut of the root of the webserver, but
it is not working.
<div
onmouseover="th is.style.backgr oundImage='url( ~/images/design/topnav01.gif)'"
/> // not working.
How to solve this???

Thanks.
Mar 17 '06 #1
6 2702
> I tried use the '~' character as shortcut of the root of the webserver,
but it is not working.
<div
onmouseover="th is.style.backgr oundImage='url( ~/images/design/topnav01.gif)'"
/> // not working.
How to solve this???


Try this:
onmouseover="th is.style.backgr oundImage='url(/images/design/topnav01.gif)'"

That's how I have things set up in my master page, and it's working fine.

--Rob Roberts
Mar 17 '06 #2
Have you tried it in the other pages that are physicaly in another subfolder
than masterpage?

I solved that by this.

onmouseover="th is.className='d ivTopMenuButton Hover01'"

and in CSS Stylesheet file I have referenced images by this way:

background-image: url(../images/design/topnav05.gif);

Because!!!: Partial URLs are interpreted relative to the source of the style
sheet, not relative to the document.
"Rob Roberts" <ro************ @AndThisToo.pci sys.net> wrote in message
news:ej******** ******@TK2MSFTN GP12.phx.gbl...
I tried use the '~' character as shortcut of the root of the webserver,
but it is not working.
<div
onmouseover="th is.style.backgr oundImage='url( ~/images/design/topnav01.gif)'"
/> // not working.
How to solve this???


Try this:
onmouseover="th is.style.backgr oundImage='url(/images/design/topnav01.gif)'"

That's how I have things set up in my master page, and it's working fine.

--Rob Roberts

Mar 17 '06 #3
"Mirek Endys" <Mi****@communi ty.nospam> wrote in message
news:ul******** ******@tk2msftn gp13.phx.gbl...
Have you tried it in the other pages that are physicaly in another
subfolder than masterpage?


Yes. My master page is located in a subfolder. None of the content pages
are located in that subfolder. I have content pages in the root folder of
the site and in various other subfolders, and they all find the paths
referred to in the master page just fine. A path like
/images/design/topnav01.gif should mean that the images folder is a
subfolder directly under the root folder of the site.

--Rob Roberts
Mar 17 '06 #4
Hi Mirek,

As for the image (or other resource) path in CSS style sheet, it can not
utilize "~" mark since it is an ASP.NET specific mark while css style is
static resource which is not parsed by ASP.NET runtime. Also, if we use
relative path in css style, the actual full-path it associate does vary
when the sheet is linked by pages in different folder hierarchy in the web
application(in application root or in sub dir...). And for such scenario,
I think we can consider the following approach:

1. Use the absolute path start from the IIS site root as Rob has mentioned.
The path starting from "/" means it start from the IIS site root(or
application root). So if you can ensure that the web application's
application root dir's name, you can make use of such style path in the css
style

2. Use separate css style for pages in different folder hierarchy in the
web application. Thus, we can put specific relative path in the specific
style sheet for a certain folder hierarchy in the application.

In addition, there exists an html <base> tag setting which can define the
url base for a certain page so that other relative path will be based on
this base path. You can have a look at the following reference for detail
description:

http://www.w3.org/TR/REC-html40/stru....html#h-12.4.1

Hope this helps some.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 20 '06 #5
I use the absolute path "/" when I can't use a server control (then I
would use "~") for something in my apps. Trouble is, it still doesn't
work properly when you run the site in file system mode. This is
because the site gets loaded like a subfolder (e.g.
"http://localhost:4582/mysite.com"). This causes the "/" to map
improperly. However, when you deploy the same site everything
maps/works fine ("http://localhost"). I really wish there was a
solution to fix this. It is reasonable that one might not be able to
use server controls for everything, and that one might want to run the
site in file system mode during development.

JP

Mar 20 '06 #6
Hi Joey,

Thanks for your inputs and kind feedback.

I've also seen some other community guys talking about the web
application's virutal path when hosting in VS 2005/.NET 2.0's test
server(file system based). Actually currently we have a workaround which is
to explicitly launch a test server instance externally , then we can set
its virtual path to the site root. Here is a good blog article discussing
on this:

#How to Run a Root ¡°/¡± Site with the VS/VWD 2005 Local Web Server
http://weblogs.asp.net/scottgu/archi...21/431138.aspx

regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 21 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3509
by: sasquatch | last post by:
Hi, I've a a site with nested master pages and content pages. I tried using a theme with a stylesheet in the app_themes directory referencing it in the web.config file from a pages tag theme attribute. This works for the content pages, but it doesn't seem able to apply the styles to the top master page even though I did set the master head tag to runat server. Is this by design? If so, what is the best way to apply styles to the top...
9
4352
by: Leffe Andersson | last post by:
Hi folks! I have a MasterPage with some public methods, and I would like to call them from a (app_code) class. Is it possible to set a directive or an assembly reference to a MasterPage from a normal class? I have no problem to call the masterpage's methods from a contentpage, but what I would like to do is someting like this... public partial class MyMaster : System.Web.UI.MasterPage
9
1915
by: User | last post by:
OK, I asked in a reply, but I've wasted far too long so I'm going to put a new post out there in hopes that it will be more visible. I have a MasterPage. I want to call a method declared in that class from a Page that uses the MasterPage. How do I do that? public partial class List : System.Web.UI.MasterPage { protected ArrayList m_SortList;
3
2087
by: Alex Maghen | last post by:
Hi. I'm a little confused about the code that resides in the code-behind of a MasterPage and the code that resides in the code-behind of the actual pages that USE that MasterPage. I'm noticing, for example, that the Page_Load on the specific page executes before the Page_Load of its MasterPage. Is this right? But what I really want to understand is VARIABLE SCOPE, etc. between the two. For example: Is there a way for me to write code...
1
1264
by: spelunka | last post by:
Hello, does anyone know why one would lose their styles after successfully authenticating against forms auth? I'm using asp.net 2.0 and the page that is being redirected to after authenticating is a content page created from a masterpage.master. Styles are lost on all controls on all content pages not just the main content page. Thanks in advance for any suggestions. Jon
5
1742
by: Islamegy® | last post by:
In my project i have two master page which i change dynamic in runtime.. The first one with 1 ContentPanel "onepanel.master", the second with 2 contentPanel"twopanel.master".. but when i switch between them it don't work, if the default masterpage is "onepanel.master" and try to change it in runtime, ContentPanel2 which is exist in the loaded masterpage throw exception.. the same happen if the default is "twopanel.master" and switch it...
4
1621
by: cevans | last post by:
Is there a way to load a MasterPage programmatically? Not switch a page's masterpage but to create a MasterPage object that holds a given masterpage. So I know I can do: MasterPage master = new MasterPage(); But there is no way to do something like: MasterPage master = new MasterPage("~/default.master");
7
13046
by: Bon | last post by:
Dear all I create a master page with image buttons on the left-hand side for navigation. When a user clicks the student button, the content (i.e. ContentPlaceholder) in masterpage will be changed from default.aspx to students.aspx. I tried to create a subroutine in MasterPage.master.vb to do it. The code is as following. But, the default.aspx's content is shown in MasterPage even I clicked the student button.
2
9002
by: Frank Milverckowitz | last post by:
Hi, New to .NET... question about Masterpages vs. using Frameset I'm using Visual Studio 2005 and notice that the generated pages are of DTD/Doctype that don't support framesets. To use framesets I will be changing all pages to HTML 4.0 loose.dtd. I have a demand from my boss to use framesets to create a "keep-alive" feature using a parent frame + ajax call on a time interval. (i.e. have the
0
9497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.