S
Steve Franks
What is the proper/best way to dynamically change the HTML written out to
the browser based on the value from a variable in a code behind page?
For instance, I have test.aspx.vb as a code behind page. In this code
behind's Page_Load event which sets a boolean called useAlternateStyle to
true or false based on business logic.
Now from my main page (test.aspx) I want to either write out HTML that sets
the style sheet to "mainStyle.css" or "alternateStyle.css" depending on the
value of this useAlternateStyle variable.
What is the best way to do this?
One way I know is to create the useAlternateStyle variable as a public or
protected variable within the code behind's class. And then in my .aspx
file I could do this in the HEAD section:
<%
if useAlternateStyle = true then
Response.Write("<link href=""alternateStyle.css"" rel=""stylesheet""
type=""text/css"" />")
else
Response.Write("<link href=""mainStyle.css"" rel=""stylesheet""
type=""text/css"" />")
end if
%>
However this seems like the old school way of doing this sort of thing. Is
there a better way?
For example, I'd prefer to somehow have a control that does a runat=server
or something that can dynamically set the name of the stylesheet. Like:
<asp:somecontrol value=getStyleSheetNameToUseFromVariable runat=server>
or something like this.
Any advise? Thanks very much in advance.
Steve
the browser based on the value from a variable in a code behind page?
For instance, I have test.aspx.vb as a code behind page. In this code
behind's Page_Load event which sets a boolean called useAlternateStyle to
true or false based on business logic.
Now from my main page (test.aspx) I want to either write out HTML that sets
the style sheet to "mainStyle.css" or "alternateStyle.css" depending on the
value of this useAlternateStyle variable.
What is the best way to do this?
One way I know is to create the useAlternateStyle variable as a public or
protected variable within the code behind's class. And then in my .aspx
file I could do this in the HEAD section:
<%
if useAlternateStyle = true then
Response.Write("<link href=""alternateStyle.css"" rel=""stylesheet""
type=""text/css"" />")
else
Response.Write("<link href=""mainStyle.css"" rel=""stylesheet""
type=""text/css"" />")
end if
%>
However this seems like the old school way of doing this sort of thing. Is
there a better way?
For example, I'd prefer to somehow have a control that does a runat=server
or something that can dynamically set the name of the stylesheet. Like:
<asp:somecontrol value=getStyleSheetNameToUseFromVariable runat=server>
or something like this.
Any advise? Thanks very much in advance.
Steve