views:

208

answers:

2

Learning how to do a master page in asp.net. Trying to figure out how my style sheet interacts with respects to the master page and content page. I can get HTML tags like body and the style sheet to react. But when I call the ID attribute of a label no styling takes place. What am I missing here as far as interaction? BTW I'm using VS2008

CSS sample:

body
 {
 height:1200px;
 width:920px;
 border-style:solid;
 border-color:blue;
 padding:10px 10px 10px 10px;
 }

 #toptext1
 {
 position:relative;
 top:-225px;
 right:-500px;
 font-size:22px;
 font-weight:bold;
 }

From the master page:

  <body>
  <form id="form1" runat="server">
         <asp:image  id="cookNookLogo" ImageUrl="images/Logo.gif" runat="server" 
         AlternateText="CookNook" Width="449px"></asp:image>
  <p>
     <asp:Label ID="toptext1" runat="server" Text="Quality Recipes, Hints and    Supplies"></asp:Label>

</p>

From the content page:

 <%@ Page Language="C#" MasterPageFile="~/CNMasterPage.master" AutoEventWireup="true"      CodeFile="Home.aspx.cs" Inherits="Home" Title="Untitled Page" %>

 <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

 <link href="App_Themes/cn/cn.css" rel="stylesheet" type="text/css" />

 </asp:Content>

When I was doing this without a master page it worked so where am I going wrong with the attributes?

+2  A: 

If you look at the generated source code for your page, you'll see that .NET has replaced your id with a far more detailed id, specifying the container and the section that it is in.

Looking at your code, the id is probably something like: c100_toptext1 (though it depends on the version of .NET that you are using)

Sean Vieira
+3  A: 

You could have something like this instead

CSS

.toptext1
 {
 position:relative;
 top:-225px;
 right:-500px;
 font-size:22px;
 font-weight:bold;
 }

ASPX

<asp:Label ID="toptext1" runat="server" CssClass="toptext1" Text="Quality
 Recipes, Hints and    Supplies"></asp:Label>

As Sean Vieira remarked. The id you assign to a web control is not the same id sent to the browser.

Here you have a good tutorial explaining how .NET manage IDs for web controls.

http://www.asp.net/LEARN/master-pages/tutorial-05-vb.aspx

Claudio Redi
The id you assign to a web control is not the same id sent to the browser. ....The things I overlook when learning a new language.Thanks!
Matt