473,395 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Use of CSS and Master Pages

I'm not sure if this is the right place to ask this question, but if there is
a better place, I cannot find it.

I have a web that uses Master Pages. The basic layout is acieved using
<table- this method is deprecated and I am trying to convert it to use CSS.
I understand CSS pretty well, and did a small pilot to see how it would all
work. Then I decided to do it on the real project.

Let's just take one small simple example that illustrates the problem. Let's
say I have within my Master Page a div, coded as follows:

<div id="logodiv" runat="server"><img src="mylogo.jpg" /></div>

And now let's suppose in the CSS file I have something like:

#logodiv { vertical-align: middle; float: left }

All should be hunky dory, but alas, it isn't because by the time the browser
sees the HTML they id of the div isn't logodiv anymore but, say _ctl0_logodiv.

Obviously, I could change the CSS file to hard code _ctl0_logodiv instead of
logodiv, but this is clearly not good.

Similarly, I could put in the .cs file a statement like:

logodiv.style = "vertical-align: middle; float: left";

But this defeats the purpose since I am trying to put the STYLE in the CSS,
and the code in the .cs and the content in the .master

How am I supposed to resolve this problem?
May 2 '07 #1
4 4576
Martin,

Two possible solutions:
- first, as your div is a logo div - there is no need to run it at server -
remove runat tag - your css will work;
- second, as you may have other elements that you need to control on the
server side - use class (CssClass) attribute/property to define your css
styles - do not rely on element IDs

HTH

"Martin Horton" wrote:
I'm not sure if this is the right place to ask this question, but if there is
a better place, I cannot find it.

I have a web that uses Master Pages. The basic layout is acieved using
<table- this method is deprecated and I am trying to convert it to use CSS.
I understand CSS pretty well, and did a small pilot to see how it would all
work. Then I decided to do it on the real project.

Let's just take one small simple example that illustrates the problem. Let's
say I have within my Master Page a div, coded as follows:

<div id="logodiv" runat="server"><img src="mylogo.jpg" /></div>

And now let's suppose in the CSS file I have something like:

#logodiv { vertical-align: middle; float: left }

All should be hunky dory, but alas, it isn't because by the time the browser
sees the HTML they id of the div isn't logodiv anymore but, say _ctl0_logodiv.

Obviously, I could change the CSS file to hard code _ctl0_logodiv instead of
logodiv, but this is clearly not good.

Similarly, I could put in the .cs file a statement like:

logodiv.style = "vertical-align: middle; float: left";

But this defeats the purpose since I am trying to put the STYLE in the CSS,
and the code in the .cs and the content in the .master

How am I supposed to resolve this problem?
May 2 '07 #2
The use of element ids in CSS is very limited, because it confines the scope
of the style to a single element. The use of CSS classes, on the other hand,
allows you to apply the same style to an entire group of elements with a
single expression. There are other selectors as well which come in handy,
including element name selectors, contextual selectors, attribute selectors,
etc. To take full advantage of the power of CSS, it's good to know what they
all are, and when to use which ones.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"Sergey Poberezovskiy" <Se*****************@discussions.microsoft.comwrot e
in message news:23**********************************@microsof t.com...
Martin,

Two possible solutions:
- first, as your div is a logo div - there is no need to run it at
server -
remove runat tag - your css will work;
- second, as you may have other elements that you need to control on the
server side - use class (CssClass) attribute/property to define your css
styles - do not rely on element IDs

HTH

"Martin Horton" wrote:
>I'm not sure if this is the right place to ask this question, but if
there is
a better place, I cannot find it.

I have a web that uses Master Pages. The basic layout is acieved using
<table- this method is deprecated and I am trying to convert it to use
CSS.
I understand CSS pretty well, and did a small pilot to see how it would
all
work. Then I decided to do it on the real project.

Let's just take one small simple example that illustrates the problem.
Let's
say I have within my Master Page a div, coded as follows:

<div id="logodiv" runat="server"><img src="mylogo.jpg" /></div>

And now let's suppose in the CSS file I have something like:

#logodiv { vertical-align: middle; float: left }

All should be hunky dory, but alas, it isn't because by the time the
browser
sees the HTML they id of the div isn't logodiv anymore but, say
_ctl0_logodiv.

Obviously, I could change the CSS file to hard code _ctl0_logodiv instead
of
logodiv, but this is clearly not good.

Similarly, I could put in the .cs file a statement like:

logodiv.style = "vertical-align: middle; float: left";

But this defeats the purpose since I am trying to put the STYLE in the
CSS,
and the code in the .cs and the content in the .master

How am I supposed to resolve this problem?

May 2 '07 #3
Firstly I would like to thank both of the people who replied to my question
for their time. As it happens, I was aware of both of these solutions.
However, this isn't really a proper solution and it seems to me this is a
hole in .Net that MS should address.

There is a good reason why CSS allows IDs to be used as selctors. It's not
really for MS to decide unilaterally that selector IDs are unnecessary.

When ASPs were invented they were the best thing since sliced bread. But it
didn't take long before people realized that mingling the HTML with the
business logic was a mistake. Thus MS invented ASP.Net and it was an amazing
advance.

I see the ability to break out the formatting from the .aspx file, into a
separate .css file as a similarly huge step. I think MS needs to give a lot
of thought in making sure the full power of CSS is available in .Net rather
than limiting it.

The use of element IDs in this case is entirely appropriate because in this
case, limiting the formatting to a single element is exactly what is intended.

Maybe what is really needed is some kind of "code-behind' file for .css
files that allows for their transformation.

"Kevin Spencer" wrote:
The use of element ids in CSS is very limited, because it confines the scope
of the style to a single element. The use of CSS classes, on the other hand,
allows you to apply the same style to an entire group of elements with a
single expression. There are other selectors as well which come in handy,
including element name selectors, contextual selectors, attribute selectors,
etc. To take full advantage of the power of CSS, it's good to know what they
all are, and when to use which ones.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"Sergey Poberezovskiy" <Se*****************@discussions.microsoft.comwrot e
in message news:23**********************************@microsof t.com...
Martin,

Two possible solutions:
- first, as your div is a logo div - there is no need to run it at
server -
remove runat tag - your css will work;
- second, as you may have other elements that you need to control on the
server side - use class (CssClass) attribute/property to define your css
styles - do not rely on element IDs

HTH

"Martin Horton" wrote:
I'm not sure if this is the right place to ask this question, but if
there is
a better place, I cannot find it.

I have a web that uses Master Pages. The basic layout is acieved using
<table- this method is deprecated and I am trying to convert it to use
CSS.
I understand CSS pretty well, and did a small pilot to see how it would
all
work. Then I decided to do it on the real project.

Let's just take one small simple example that illustrates the problem.
Let's
say I have within my Master Page a div, coded as follows:

<div id="logodiv" runat="server"><img src="mylogo.jpg" /></div>

And now let's suppose in the CSS file I have something like:

#logodiv { vertical-align: middle; float: left }

All should be hunky dory, but alas, it isn't because by the time the
browser
sees the HTML they id of the div isn't logodiv anymore but, say
_ctl0_logodiv.

Obviously, I could change the CSS file to hard code _ctl0_logodiv instead
of
logodiv, but this is clearly not good.

Similarly, I could put in the .cs file a statement like:

logodiv.style = "vertical-align: middle; float: left";

But this defeats the purpose since I am trying to put the STYLE in the
CSS,
and the code in the .cs and the content in the .master

How am I supposed to resolve this problem?


May 2 '07 #4
A CSS class can apply to a single element, as long as the element has a
unique class name. The only difference is the selector syntax. If a CSS
selector is for an element ID, the element must have a unique id. I don't
see the issue here.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"Martin Horton" <Ma**********@discussions.microsoft.comwrote in message
news:01**********************************@microsof t.com...
Firstly I would like to thank both of the people who replied to my
question
for their time. As it happens, I was aware of both of these solutions.
However, this isn't really a proper solution and it seems to me this is a
hole in .Net that MS should address.

There is a good reason why CSS allows IDs to be used as selctors. It's not
really for MS to decide unilaterally that selector IDs are unnecessary.

When ASPs were invented they were the best thing since sliced bread. But
it
didn't take long before people realized that mingling the HTML with the
business logic was a mistake. Thus MS invented ASP.Net and it was an
amazing
advance.

I see the ability to break out the formatting from the .aspx file, into a
separate .css file as a similarly huge step. I think MS needs to give a
lot
of thought in making sure the full power of CSS is available in .Net
rather
than limiting it.

The use of element IDs in this case is entirely appropriate because in
this
case, limiting the formatting to a single element is exactly what is
intended.

Maybe what is really needed is some kind of "code-behind' file for .css
files that allows for their transformation.

"Kevin Spencer" wrote:
>The use of element ids in CSS is very limited, because it confines the
scope
of the style to a single element. The use of CSS classes, on the other
hand,
allows you to apply the same style to an entire group of elements with a
single expression. There are other selectors as well which come in handy,
including element name selectors, contextual selectors, attribute
selectors,
etc. To take full advantage of the power of CSS, it's good to know what
they
all are, and when to use which ones.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"Sergey Poberezovskiy" <Se*****************@discussions.microsoft.com>
wrote
in message news:23**********************************@microsof t.com...
Martin,

Two possible solutions:
- first, as your div is a logo div - there is no need to run it at
server -
remove runat tag - your css will work;
- second, as you may have other elements that you need to control on
the
server side - use class (CssClass) attribute/property to define your
css
styles - do not rely on element IDs

HTH

"Martin Horton" wrote:

I'm not sure if this is the right place to ask this question, but if
there is
a better place, I cannot find it.

I have a web that uses Master Pages. The basic layout is acieved using
<table- this method is deprecated and I am trying to convert it to
use
CSS.
I understand CSS pretty well, and did a small pilot to see how it
would
all
work. Then I decided to do it on the real project.

Let's just take one small simple example that illustrates the problem.
Let's
say I have within my Master Page a div, coded as follows:

<div id="logodiv" runat="server"><img src="mylogo.jpg" /></div>

And now let's suppose in the CSS file I have something like:

#logodiv { vertical-align: middle; float: left }

All should be hunky dory, but alas, it isn't because by the time the
browser
sees the HTML they id of the div isn't logodiv anymore but, say
_ctl0_logodiv.

Obviously, I could change the CSS file to hard code _ctl0_logodiv
instead
of
logodiv, but this is clearly not good.

Similarly, I could put in the .cs file a statement like:

logodiv.style = "vertical-align: middle; float: left";

But this defeats the purpose since I am trying to put the STYLE in the
CSS,
and the code in the .cs and the content in the .master

How am I supposed to resolve this problem?



May 3 '07 #5

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

Similar topics

1
by: Sasha | last post by:
Hi all asp.net proffesionals out there, How do you implement master pages in your applications? What libraries do you use and what have been your experience? Sasha
5
by: Michael Herman \(Parallelspace\) | last post by:
1. What are some compelling solutions for using Master/Content pages with Web Pages? 2. If a content area has a web part zone with web parts, what is the user experience like when "editting" the...
20
by: Alan Silver | last post by:
Hello, In classic ASP, I used to use two include files on each page, one before and one after the main content, to provide a consistent layout across a web site. That way I could just change the...
1
by: Alan Silver | last post by:
Hello, I am just experimenting with master pages, and am trying to add a content placeholder in the <head> section, so that individual pages can set their own page title and meta tags. The...
17
by: Rob R. Ainscough | last post by:
Again another simple concept that appears NOT to be intuitive or I'm just stupid. I've read the WROX book and the example doesn't actually show how the .master page links in the other content...
7
by: xkeops | last post by:
Thinking of creating a website, most of the pages will have a general toolbar menu, a content and a footer. The content will be the only one who's gonna change but the rest (header,footer) will...
8
by: JT | last post by:
Hi, I have done a fair amount of style editing inline in ASP. I'm now using VS 2005 with a standard web project (not Web Application Project). This is my first foray into CSS in a style sheet...
3
by: Rich | last post by:
Hi, I want to use 2 master pages, one for the main part of the site, the other for the admin pages. They are quite similar, with many shared elements. Ideally I would like to have a parent...
13
by: Kirk | last post by:
I have been reading Scott Allen's article on Master Pages (http:// odetocode.com/Articles/450.aspx) but I am having problems understanding a concept. Specifically, I have created a property...
6
by: Mickey | last post by:
Coming from a Dreamweaver/ASP/PHP background. Planning to use Visual Studio 2008 for a website. Complete newbie question here (please be gentle!): Do master pages work similar to Dreamweaver...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...

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.