Desperate! CSS + Session + SQL Server with C# ASP.NET
-
Hi fellas, I'm stuck big time with my site. I'll try to make it short and simple. I am currently trying to write a website in the C# of ASP.NET. I am writing it in VS.NET 2003. I needed to use CSS for flexibility, so I decided to store the values of the CSS in a SQL Server Express 2005 Database. I also use a lot of user controls, I used a user control for my tabs on the site, another for the list buttons. However since there are quite a few pages in the site, I decided to use the external style sheets, since updating them would make my life easier. After the CSS values is retrieved, the values are stored in a session variable, then the style sheet links with the CSS session variables. I have placed the database connection in the very first line of the Page_load of the index.aspx. The problem is, it seems the CSS values are never loaded. Here's what I've tried and done: 1. Using internal style sheet (by placing it in the HEAD header) seems fine, the CSS worked. 2. I am certain the database connection is fine; I made a dummy label on the index.aspx, and I was managed to print the value from the database onto the Label. Therefore I am suspecting the culprit is the user Controls are loaded first, then the database. Therefore the CSS could never retreive the CSS values from the database. Could there be anything else? I am stuck big time. HELP!!!
I don't see the point in storing your CSS in your database. There probably isn't one. Either way, I would say the first step is to remove them from the DB, so you can establish if the DB is the point of failure. Load them from a local path, then if that works, look at your DB code.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
I don't see the point in storing your CSS in your database. There probably isn't one. Either way, I would say the first step is to remove them from the DB, so you can establish if the DB is the point of failure. Load them from a local path, then if that works, look at your DB code.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
I guess I forgot to mention the reason I am storing it in the database it because I want the user to be able to set different color schemes for the site.
-
I guess I forgot to mention the reason I am storing it in the database it because I want the user to be able to set different color schemes for the site.
i think might be you are doing in wrong place try to do it page init/pri int events then see ...
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
I guess I forgot to mention the reason I am storing it in the database it because I want the user to be able to set different color schemes for the site.
OK, either way, I'd be removing the database stuff, it just makes sense to work out if the DB is the source of hte problem or not, even if it's just a starting point to fixing it with the DB. I presume you've checked that the CSS is in the final HTML.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
i think might be you are doing in wrong place try to do it page init/pri int events then see ...
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
Thanks for the replies. I am quite certain the Database itself is fine. I experimented by placing the database connection codes right under the Page_Load section of index.aspx. Then I created a dummy label on the index.aspx, and have it print out one of the values retreived from the database onto the label. Worked fine. Is there anywhere else I can store the database connection codes? I thought placing it under the Page_Load is pretty much the best bet. I just can't think of anywhere else. I do need to know does VS loads the user controls first, then it loads the Page_Load of the index.aspx.
-
OK, either way, I'd be removing the database stuff, it just makes sense to work out if the DB is the source of hte problem or not, even if it's just a starting point to fixing it with the DB. I presume you've checked that the CSS is in the final HTML.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
Thanks for the reply. I am certain the DB is fine. I am stuck with the following: My index.aspx is basically filled with user controls. Some of the CSS settings also applies to the user controls. Therefore I have external Style sheet links within the user control files too. My question is when the index.aspx is loaded, does it first load the user control files that are linked with the index.aspx, then it loads the Page_Load of the index.aspx, where the database codes are stored. This is the only reasonable explanation I can come up with, since when the User Controls are loaded the DB connection codes aren't executed yet. Any ideas? Double thanks! This is driving me nuts....
-
Thanks for the reply. I am certain the DB is fine. I am stuck with the following: My index.aspx is basically filled with user controls. Some of the CSS settings also applies to the user controls. Therefore I have external Style sheet links within the user control files too. My question is when the index.aspx is loaded, does it first load the user control files that are linked with the index.aspx, then it loads the Page_Load of the index.aspx, where the database codes are stored. This is the only reasonable explanation I can come up with, since when the User Controls are loaded the DB connection codes aren't executed yet. Any ideas? Double thanks! This is driving me nuts....
Infernojericho wrote:
My question is when the index.aspx is loaded, does it first load the user control files that are linked with the index.aspx, then it loads the Page_Load of the index.aspx, where the database codes are stored.
In Page Life Cycle Page Initialization is fired from child control to parent control means User control will get initilazed first then Page but Page load will always fire from Parent control to child means Page Load will occur first then user control load will occur do one thing just try to debug your application and check are you able to set style sheet in page load ?
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
Infernojericho wrote:
My question is when the index.aspx is loaded, does it first load the user control files that are linked with the index.aspx, then it loads the Page_Load of the index.aspx, where the database codes are stored.
In Page Life Cycle Page Initialization is fired from child control to parent control means User control will get initilazed first then Page but Page load will always fire from Parent control to child means Page Load will occur first then user control load will occur do one thing just try to debug your application and check are you able to set style sheet in page load ?
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
Thanks for the reply. This is the entire content of the CSS style sheet. The code worked when it was an internal style sheet (inside the . I simply copied and pasted it to a new file, styles.css. Or am I missing something here?
<style type="text/css"> <!-- /* CSS Tabs */ #navlist { padding: 3px 0; margin-left: 0; border-bottom: 1px solid <%=Session["common_borderlinecolor"]%>; /* LINE BORDER, THICKNESS OF LINE */ font: <%=Session["tab_fontstyle"] + " " + Session["tab_fontsize"] + "px " + Session["common_fontname"]%>, sans-serif; } #navlist li { list-style: none; margin: 0; display: inline; } #navlist li a { padding: 3px 0.5em; margin-left: 3px; border: 1px solid <%=Session["tab_borderlinecolor"]%>; /* LINE BORDER */ border-bottom: none; background: <%=Session["tab_mouseawaybgcolor"]%>; /* TAB BACKGROUND OF REGULAR TABS */ text-decoration: none; } #navlist li a:link { color: <%=Session["tab_unvisitedfontcolor"]%>; } /* FONT COLOR */ #navlist li a:visited { color: <%=Session["tab_visitedfontcolor"]%>; } #navlist li a:hover { color: <%=Session["tab_mouseoverfontcolor"]%>; /* COLOR OF FONT IN TAB WHEN MOUSE OVER */ background: <%=Session["tab_mouseoverbgcolor"]%>; /* COLOR OF TAB BACKGROUND WHEN MOUSE OVER */ border-color: <%=Session["tab_mouseoverbordercolor"]%>; /* COLOR OF TAB BORDER WHEN MOUSE OVER */ } #navlist li a#current { background: <%=Session["tab_currentbgcolor"]%>; border-bottom: 1px solid white; } --> </style>
-
Thanks for the reply. This is the entire content of the CSS style sheet. The code worked when it was an internal style sheet (inside the . I simply copied and pasted it to a new file, styles.css. Or am I missing something here?
<style type="text/css"> <!-- /* CSS Tabs */ #navlist { padding: 3px 0; margin-left: 0; border-bottom: 1px solid <%=Session["common_borderlinecolor"]%>; /* LINE BORDER, THICKNESS OF LINE */ font: <%=Session["tab_fontstyle"] + " " + Session["tab_fontsize"] + "px " + Session["common_fontname"]%>, sans-serif; } #navlist li { list-style: none; margin: 0; display: inline; } #navlist li a { padding: 3px 0.5em; margin-left: 3px; border: 1px solid <%=Session["tab_borderlinecolor"]%>; /* LINE BORDER */ border-bottom: none; background: <%=Session["tab_mouseawaybgcolor"]%>; /* TAB BACKGROUND OF REGULAR TABS */ text-decoration: none; } #navlist li a:link { color: <%=Session["tab_unvisitedfontcolor"]%>; } /* FONT COLOR */ #navlist li a:visited { color: <%=Session["tab_visitedfontcolor"]%>; } #navlist li a:hover { color: <%=Session["tab_mouseoverfontcolor"]%>; /* COLOR OF FONT IN TAB WHEN MOUSE OVER */ background: <%=Session["tab_mouseoverbgcolor"]%>; /* COLOR OF TAB BACKGROUND WHEN MOUSE OVER */ border-color: <%=Session["tab_mouseoverbordercolor"]%>; /* COLOR OF TAB BORDER WHEN MOUSE OVER */ } #navlist li a#current { background: <%=Session["tab_currentbgcolor"]%>; border-bottom: 1px solid white; } --> </style>
My Friend you are adding Style sheet dynamically. i think you should do that before page gets load i think Page Pre init is good event to do this. Just try to put your code there it shouild work i think there ia no problem in your CSS
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
My Friend you are adding Style sheet dynamically. i think you should do that before page gets load i think Page Pre init is good event to do this. Just try to put your code there it shouild work i think there ia no problem in your CSS
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
Thanks for the reply. Here's the problem. The database connection codes are at the page load section. What the DB codes does is it connects to the db, retreives the CSS values, then stores the CSS values in a session variable. However if the CSS style sheet goes before the db connection then the CSS style sheet won't receive any values???!!! Thanks
-
Hi fellas, I'm stuck big time with my site. I'll try to make it short and simple. I am currently trying to write a website in the C# of ASP.NET. I am writing it in VS.NET 2003. I needed to use CSS for flexibility, so I decided to store the values of the CSS in a SQL Server Express 2005 Database. I also use a lot of user controls, I used a user control for my tabs on the site, another for the list buttons. However since there are quite a few pages in the site, I decided to use the external style sheets, since updating them would make my life easier. After the CSS values is retrieved, the values are stored in a session variable, then the style sheet links with the CSS session variables. I have placed the database connection in the very first line of the Page_load of the index.aspx. The problem is, it seems the CSS values are never loaded. Here's what I've tried and done: 1. Using internal style sheet (by placing it in the HEAD header) seems fine, the CSS worked. 2. I am certain the database connection is fine; I made a dummy label on the index.aspx, and I was managed to print the value from the database onto the Label. Therefore I am suspecting the culprit is the user Controls are loaded first, then the database. Therefore the CSS could never retreive the CSS values from the database. Could there be anything else? I am stuck big time. HELP!!!
U can use css in Your VS2003, It will save all this session problems that curruntly u have so it will be better to Include Css in Project itself. And yes what u say
"external style sheets, since updating them would make my life easier"
While running the project u don't need to restart it again if u make changes in css. So it is not the case while codding in Code behind file.
Believe Yourself™ :->™
-
Thanks for the replies. I am quite certain the Database itself is fine. I experimented by placing the database connection codes right under the Page_Load section of index.aspx. Then I created a dummy label on the index.aspx, and have it print out one of the values retreived from the database onto the label. Worked fine. Is there anywhere else I can store the database connection codes? I thought placing it under the Page_Load is pretty much the best bet. I just can't think of anywhere else. I do need to know does VS loads the user controls first, then it loads the Page_Load of the index.aspx.
User Control Won't be going to help anymore. And Yes First U.C will be loaded and then Page. Put a Break point on U.C's Page Load. U will get it.
Believe Yourself™ :->™