I have inherited an older asp site which was recently upgraded to .NET 4.0. However, it does not use master pages. Instead, it makes references to various user controls at the top of all the aspx pages. There is a particular user control that is at the top
of most of the pages, so I experimented with adding a scriptmanager in there hoping it would be seen everywhere. However, I cannot get it to work accurately. Any ajaxcontroltoolkit item I place in that user control works fine, but when I try to use something
within an aspx page it says the scriptmanager is not there. Then, if I just hack around and add another script manager to the aspx page, it goes on to tell me that I cannot have two of them on the page. It seemingly says one thing and then another.
So, I tried to also scope out adding a master page to the site and referencing it with all of my aspx pages, but that seems to be something I don't want to do as I would be editing all of the pages (unless you guys know something I don't about making this
task easier?).
Is there a best practice and, hopefully, straightforward and easy way to pull this task off?
My ultimate goal in mind that started me on this path, by the way, was that I needed to add a balloon popup to a cart which sits up in one of the user controls up top. I would need to call upon this balloon at any time from within any aspx page. So, ideally,
if that problem could be solved easily then these other ideas could be done away with completely.
You would need to have that script manager on every page. The controls used on that page will inherit and use the script manager on the page. For instance if you have a ManageProfile.asxc file on Page1.aspx and Page3.aspx you would not place the ScriptManager
on the ManageProfile.ascx file but in the Page1 and Page3.aspx files. This way you won't run into conflicts. Ideally, master pages would be your best bet but depending on the size of the site, that may require some work.
Remember to mark as answer if this post answered or solved your problem.
Marked as answer by palpacino on Apr 26, 2012 07:48 PM
It looks like I will need to add a scriptmanager to the top of the <FORM> tags to almost all of the aspx pages in this site. That is still easier, I believe, than retrofitting all of them and their respective unique coding to fit into master pages individually.
The assumption I am making that all each of these aspx pages will need in my case is a <scriptmanager> at the top of them before their references to the custom controls, correct?
Well, I figured out what I was doing wrong and why it seemed to be inconsistently telling me things about the scriptmanager. There was some inline code at the top of the ascx file that I was trying to add this scriptmanager to. The first line in that inline
code was an IF block. So sometimes it would render my scriptmanager and sometimes it wouldn't. A complete oversight on my part. I mean the code is ugly, but I should have seen that.
So with that being said, I was able to add a script manager to the user control that is at the top of all of our pages. This is essentially the same as adding a script manager to a master page in this project of ours as, like I said, the user control is
on EVERY page and is the first thing in the form tags. This thing really needs a master page structure applied to it, lol. But I digress.
I did notice one thing, b471code3. ALL of the aspx pages in this project do inline code in the HEAD tags for "dynamic" titles and CSS. See example below. So when I do this script manager in the ascx file which is the first thing in the FORM tag, suddenly
the pages start screaming that I need a runat=server tag in the HEAD tag. What the heck?
But when I do this, I get: This page is missing a HtmlHead control which is required for the CSS stylesheet link that is being added. Please add <head runat="server"
If I add the runat="server" to the HEAD tag then the CSS that is referenced in above code snippet doesn't seem to get added to the page and everything renders without any styles on the page. So, it doesn't crash. However it doesn't get CSS either. What gives?
:(
But when I do this, I get: This page is missing a HtmlHead control which is required for the CSS stylesheet link that is being added. Please add <head runat="server"
If I add the runat="server" to the HEAD tag then the CSS that is referenced in above code snippet doesn't seem to get added to the page and everything renders without any styles on the page. So, it doesn't crash. However it doesn't get CSS either. What gives?
:(
Notice that the <head> element contains a runat="server" attribute, which indicates that it is a server control (rather than static HTML). All ASP.NET pages derive from the Page class, which is located in the System.Web.UI namespace. This class contains
a Header property that provides access to the page's <head> region. Using the
Header property we can set an ASP.NET page's title or add additional markup to the rendered <head> section. It is possible, then, to customize a content page's <head> element by writing a bit of code in the page's Page_Load event handler.
Please mark the replies as answers if they help or unmark if not.
Feedback to us
You are exactly right. I failed to mention that I was aware that I could write some page_load code to set the title and even pull the CSS at that time, too. That would allow me to take both of those inline code lines out of the aspx page. However, this would
need to be done on ALL of the aspx pages in the whole project. I am trying to avoid a mass update as there are many, many files in this project. Of course, I realize that this may not be possible, but that is why I am here bugging you nice folks. :)
If I have to do a mass update on all of the aspx pages, I would just assume going ahead and giving them all a master page structure and do them the "right" way. Thank you for your assistance, Frank.
I came to the conclusion that I need to implement master pages in this whole site and get it into the current decade in order to do this correctly. Heck, Master pages are kinda last decade, eh? lol
palpacino
Member
32 Points
52 Posts
Using scriptmanager WITHOUT master pages in my site...
Mar 01, 2012 03:29 PM|LINK
I have inherited an older asp site which was recently upgraded to .NET 4.0. However, it does not use master pages. Instead, it makes references to various user controls at the top of all the aspx pages. There is a particular user control that is at the top of most of the pages, so I experimented with adding a scriptmanager in there hoping it would be seen everywhere. However, I cannot get it to work accurately. Any ajaxcontroltoolkit item I place in that user control works fine, but when I try to use something within an aspx page it says the scriptmanager is not there. Then, if I just hack around and add another script manager to the aspx page, it goes on to tell me that I cannot have two of them on the page. It seemingly says one thing and then another.
So, I tried to also scope out adding a master page to the site and referencing it with all of my aspx pages, but that seems to be something I don't want to do as I would be editing all of the pages (unless you guys know something I don't about making this task easier?).
Is there a best practice and, hopefully, straightforward and easy way to pull this task off?
My ultimate goal in mind that started me on this path, by the way, was that I needed to add a balloon popup to a cart which sits up in one of the user controls up top. I would need to call upon this balloon at any time from within any aspx page. So, ideally, if that problem could be solved easily then these other ideas could be done away with completely.
Thanks for any help, guys! :)
b471code3
Star
13877 Points
2598 Posts
Re: Using scriptmanager WITHOUT master pages in my site...
Mar 01, 2012 06:26 PM|LINK
You would need to have that script manager on every page. The controls used on that page will inherit and use the script manager on the page. For instance if you have a ManageProfile.asxc file on Page1.aspx and Page3.aspx you would not place the ScriptManager on the ManageProfile.ascx file but in the Page1 and Page3.aspx files. This way you won't run into conflicts. Ideally, master pages would be your best bet but depending on the size of the site, that may require some work.
palpacino
Member
32 Points
52 Posts
Re: Using scriptmanager WITHOUT master pages in my site...
Mar 01, 2012 07:47 PM|LINK
It looks like I will need to add a scriptmanager to the top of the <FORM> tags to almost all of the aspx pages in this site. That is still easier, I believe, than retrofitting all of them and their respective unique coding to fit into master pages individually. The assumption I am making that all each of these aspx pages will need in my case is a <scriptmanager> at the top of them before their references to the custom controls, correct?
PS - THANK YOU!
b471code3
Star
13877 Points
2598 Posts
Re: Using scriptmanager WITHOUT master pages in my site...
Mar 02, 2012 01:24 PM|LINK
Put it immediately after the form tag and you will be set to go.
palpacino
Member
32 Points
52 Posts
Re: Using scriptmanager WITHOUT master pages in my site...
Mar 05, 2012 07:17 PM|LINK
Well, I figured out what I was doing wrong and why it seemed to be inconsistently telling me things about the scriptmanager. There was some inline code at the top of the ascx file that I was trying to add this scriptmanager to. The first line in that inline code was an IF block. So sometimes it would render my scriptmanager and sometimes it wouldn't. A complete oversight on my part. I mean the code is ugly, but I should have seen that.
So with that being said, I was able to add a script manager to the user control that is at the top of all of our pages. This is essentially the same as adding a script manager to a master page in this project of ours as, like I said, the user control is on EVERY page and is the first thing in the form tags. This thing really needs a master page structure applied to it, lol. But I digress.
I did notice one thing, b471code3. ALL of the aspx pages in this project do inline code in the HEAD tags for "dynamic" titles and CSS. See example below. So when I do this script manager in the ascx file which is the first thing in the FORM tag, suddenly the pages start screaming that I need a runat=server tag in the HEAD tag. What the heck?
<head> <title><%=Me.PageTitle%>-<%=application(session("_homepagePNAME")%></title> <link href="styles/<%=Me.PageStyleSheet%>" type="text/css" rel="stylesheet"> <meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR" /> <meta content="Visual Basic 7.0" name="CODE_LANGUAGE" /> <meta content="JavaScript" name="vs_defaultClientScript" /> <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema" /> </head> <body class="default" MS_POSITIONING="GridLayout" onkeydown="checkenterkey()"> <form id="Form1" method="post" runat="server" name="Form1"> <uc1:topSection id="TopSection1" runat="server"></uc1:topSection> . . .But when I do this, I get:
This page is missing a HtmlHead control which is required for the CSS stylesheet link that is being added. Please add <head runat="server"
If I add the runat="server" to the HEAD tag then the CSS that is referenced in above code snippet doesn't seem to get added to the page and everything renders without any styles on the page. So, it doesn't crash. However it doesn't get CSS either. What gives? :(
The same thing is happening on this forum post:
http://forums.asp.net/t/1447500.aspx/1
However, that looks to be marked as resolved with no resolve.
PS - Is that a Vols cap you have, b471code3? I live in Nashville. There is beer here for ya if we get this thing working, ha! Rock n roll!
Frank Jiang ...
All-Star
16006 Points
1728 Posts
Microsoft
Re: Using scriptmanager WITHOUT master pages in my site...
Mar 06, 2012 06:17 AM|LINK
Notice that the <head> element contains a runat="server" attribute, which indicates that it is a server control (rather than static HTML). All ASP.NET pages derive from the Page class, which is located in the System.Web.UI namespace. This class contains a Header property that provides access to the page's <head> region. Using the Header property we can set an ASP.NET page's title or add additional markup to the rendered <head> section. It is possible, then, to customize a content page's <head> element by writing a bit of code in the page's Page_Load event handler.
Feedback to us
Develop and promote your apps in Windows Store
palpacino
Member
32 Points
52 Posts
Re: Using scriptmanager WITHOUT master pages in my site...
Mar 06, 2012 03:52 PM|LINK
Hi Frank,
You are exactly right. I failed to mention that I was aware that I could write some page_load code to set the title and even pull the CSS at that time, too. That would allow me to take both of those inline code lines out of the aspx page. However, this would need to be done on ALL of the aspx pages in the whole project. I am trying to avoid a mass update as there are many, many files in this project. Of course, I realize that this may not be possible, but that is why I am here bugging you nice folks. :)
If I have to do a mass update on all of the aspx pages, I would just assume going ahead and giving them all a master page structure and do them the "right" way. Thank you for your assistance, Frank.
palpacino
Member
32 Points
52 Posts
Re: Using scriptmanager WITHOUT master pages in my site...
Mar 09, 2012 11:24 PM|LINK
I came to the conclusion that I need to implement master pages in this whole site and get it into the current decade in order to do this correctly. Heck, Master pages are kinda last decade, eh? lol
Thanks for your input everyone.