Question for ASP.NET developers
#1
Question for ASP.NET developers
I want to allow users of my site to choose what CSS file the site is rendered with. I'm assuming I'll be storing that preference in cookies (since not all visitors are registered in the dB) and also also assuming that I'll applying that preference page-wise in the header.
How can I pass that variable/string from the codebehind forward into the header of the .aspx page? I've tried a line such as...
<link href="<%= CSSpreferenceString %>" type=text/css rel=stylesheet>
...but Visual Studio complains about this and highlights the <% and %> in yellow. Is there anything special about the declaration of things you want to use in the .aspx instead of the codebehind?
How can I pass that variable/string from the codebehind forward into the header of the .aspx page? I've tried a line such as...
<link href="<%= CSSpreferenceString %>" type=text/css rel=stylesheet>
...but Visual Studio complains about this and highlights the <% and %> in yellow. Is there anything special about the declaration of things you want to use in the .aspx instead of the codebehind?
#2
in the head put
<link id="selStylesheet" rel="styleSheet" runat="server"></link>
in the codebehind
Protected selStylesheet As System.Web.UI.HtmlControls.HtmlGenericControl
in the Page.Load event put
Private Sub Page_Load (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Get cookie value
selStylesheet.Attributes.Add("href", thevalue)
End Sub
u could put select case statements so that the selection stored inthe cookie isnt the url to the stylesheet but more friendly, and get the url from whereever... from constants in the code, or from appSettings in the web.config
Thats one way of doing it.
<link id="selStylesheet" rel="styleSheet" runat="server"></link>
in the codebehind
Protected selStylesheet As System.Web.UI.HtmlControls.HtmlGenericControl
in the Page.Load event put
Private Sub Page_Load (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Get cookie value
selStylesheet.Attributes.Add("href", thevalue)
End Sub
u could put select case statements so that the selection stored inthe cookie isnt the url to the stylesheet but more friendly, and get the url from whereever... from constants in the code, or from appSettings in the web.config
Thats one way of doing it.
#4
Thanks SCOSaltire. I posted the same question on another Forum and a poster over there suggested using a Literal control. Probably a "six of one, half a dozen of another" situation! Thanks, though -- I didn't know the System.Web.UI.HtmlControls.HtmlGenericControl thing existed!
Thread
Thread Starter
Forum
Replies
Last Post
Mattybr5@MB Developments
Full Cars Breaking For Spares
28
28 December 2015 11:07 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
12
18 November 2015 07:03 AM
Brzoza
Engine Management and ECU Remapping
1
02 October 2015 05:26 PM