ASP.NET 2.0 BasicsIf you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
I have a 30 page website under development where all pages derive from 1 masterpage. Using a master page precludes using the <head> tag where I could specify a <link> to an external css page - a separate one for each aspx page.
Making a big internal <style> section on the master page defeats the efficiency of a load-one-time external css page, so that's out too.
Boils down to: How to dynamically add a <link> tag to a masterpage when each aspx page loads. Anyone got an idea on how I can do that? Or some equivalent functionality? Thanks.
It explains the concepts of adding a <meta> tag to a master page that you can then set from a content page. The same principle applies to styles sheets. However, instead of adding a meta tag, add this to the head section:
Then in the code behind, you can control the MyLink tag's Href attribute like this:
MyLink.Href = "SomeNewStyleFile.css"
If you wrap the previous line in a property like StyleSheetUrl, similar to the meta tag, content pages can then programmatically set the style sheet.
Does this help?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: Spirit by Dead Can Dance (Track 9 from the album: Dead Can Dance 1981-1998 (Limited Edition) [CD2]) What's This?
Imar:
Sorry to be getting back with you so late. Got diverted to another project. You know how it is.
I have read and implemented the material you wrote and the link to topic 44971. I've had partial success in that I can *see* the master page from the content page. The unsuccessful part is that it does not work. To much to explain here.
Please visit http://www.cayuca.net . There you will see my current project. Attention to page ActivityAdd.aspx, which is the only content page developed so far.
You can view the code, but it appears to be much more complicated than it really is. So, you can also visit: http://www.cayuca.net/ActivitiesAddProblem.doc to see a more lucid writeup of what I have written. Somewhere in this MS Word doc I've made a mistake. Help please. Thanks.
Oops. Made a minor boo-boo. The css should be applied to the label: lblLeaderName
and not the textbox txtLeaderName. Doesn't make any difference tho, still does not work.
VV
Imar:
I found the html you mention. Doesn't have the double leading underscores, but is the span tag for the lblLeaderName. There is only one place where this exists.
What I did was to add three more rules in the associated css to account for all possible id-s for this label: That is: #__ctl00_ContentPlaceHolder1_lbllblLeaderName {bla), same as previous but with only one leading underscore, and same a previous but with no leading underscore: #ctl00_ContentPlaceHolder1_lbllblLeaderName {bla}.
Still no joy.
I think I am missing your point somewhere. Should I change the rendered code from the remote server at run time in some event handler? I tried moving my instantiation of the masterpage.master and resetting the css page's url code from the pre-init handler to the pre-render handler. No joy there either.
When you have a master page, you'll find that .NET changes the client side ID of your controls, to reflect the control hierarchy they're in. So, when you have a text box with an ID of txtUserName, it may come out completely different, with prefixes for the content placeholder etc.
Don't worry about the underscores. I couldn't remember the exact syntax when I typed that message, so I just made something up.
Two ways to fix it:
1. Look at the client code. If the ID is something like :
ctl00_ContentPlaceHolder1_lbllblLeaderName
then add the following to your stylesheet:
#ctl00_ContentPlaceHolder1_lbllblLeaderName
{
}
You said you habe that already, so something else must be going wrong. Make sure you applied the correct style sheet (maybe there's a path issue to the style sheet in your master page? Check the HTML source so see if the page is referencing the correct style sheet).
2. Use a class instead of an ID:
<asp:TextBox id="SomeId" CssClass="SomeClass" />
Then in your CSS add this:
.SomeClass
{
// CSS definition goes here.
}
If all this doesn't work, please post your code. For me, that works a lot better than posting links to .doc files...