|
-
Sep 6th, 2007, 09:15 AM
#1
Thread Starter
Fanatic Member
no reference to object
Whenever I try to run a page with a stylesheet link in it, I get an error that says you need runat="server" in the head tag.
So I found this and tried it in the Page_Load event
Code:
HtmlLink fred = new HtmlLink();
fred.Href = "Stylesheet.css";
fred.Attributes.Add("rel", "stylesheet");
fred.Attributes.Add("type", "text/css");
Page.Header.Controls.Add(fred);
But when I run it it says
Object reference not set to an instance of an object.
Why? When I am typing it intellisense fills it all in. I have used the 'new' keyword. What is wrong?
Thanks for any help.
-
Sep 6th, 2007, 03:55 PM
#2
Re: no reference to object
So why not just add runat="server" in the <head> tag?
<head runat="server" id="PageHead">
-
Sep 6th, 2007, 04:19 PM
#3
Thread Starter
Fanatic Member
Re: no reference to object
 Originally Posted by mendhak
So why not just add runat="server" in the <head> tag?
<head runat="server" id="PageHead">
Because if I do that the javascript I have on the page does not run. I tried moving the javascript out of the <head> and into the <body> but still does not run. This page also has Ajax controls on it. I'm beginning to think they cause problems.
What is particularly weird is that loads of pages on the site run quite happily with the usual stylesheet link in the head. The only ones that ask for runat="server" in the head tag are the ones that use the Ajax Toolkit.
-
Sep 8th, 2007, 09:19 AM
#4
Re: no reference to object
Question: Are you using themes? Even a default one? If yes, put your CSS in the default theme folder.
As for the requirement by the ajax toolkit, this is most likely because the ajax code needs to dynamically inject <script> tags into the head section, hence the runat="server" needed.
You mentioned that if you add the runat="server" your javascript stops running. (Why do you get all the weird situations?) Could you instead then attempt to use code similar to post 1 to add your javascript? Or, if it's in-page javascript code, use Page.RegisterClientScriptBlock
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|