Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to dynamically write html based on a var from code behind?

Reply
Thread Tools

How to dynamically write html based on a var from code behind?

 
 
Steve Franks
Guest
Posts: n/a
 
      08-31-2005
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


 
Reply With Quote
 
 
 
 
Lucas Tam
Guest
Posts: n/a
 
      08-31-2005
"Steve Franks" <> wrote in
news:F4WdnZ2dnZ0bcze4nZ2dnbyPiN6dnZ2dRVn-:

> 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?


If you only want to switch the style sheet, then add "runat=server"
property to the link control... now you'll have access to it in the code
behind.

Otherwise take a look at the literal control and HTMLGeneric Control.

--
Lucas Tam ()
Please delete "REMOVE" from the e-mail address when replying.

Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
 
Reply With Quote
 
 
 
 
Steve Franks
Guest
Posts: n/a
 
      08-31-2005
Thanks. However I do not see a "link" control. I have a LinkButton and
Hyperlink control, but don't think that's it.

Can you please clarify specifically what you mean by link control? Also can
you provide a one line snippet that demonstrates how a link control would be
set to a value based on a variable set within a code behind page?

Thanks,

Steve


"Lucas Tam" <> wrote in message
news:Xns96C3B13F4733nntprogerscom@127.0.0.1...
> "Steve Franks" <> wrote in
> news:F4WdnZ2dnZ0bcze4nZ2dnbyPiN6dnZ2dRVn-:
>
>> 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?

>
> If you only want to switch the style sheet, then add "runat=server"
> property to the link control... now you'll have access to it in the code
> behind.
>
> Otherwise take a look at the literal control and HTMLGeneric Control.
>
> --
> Lucas Tam ()
> Please delete "REMOVE" from the e-mail address when replying.
>
> Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between Session["var"] and Session("var") thomson ASP .Net 10 06-20-2005 01:02 PM
Difference between Session["var"] and Session("var") thomson ASP .Net 0 06-20-2005 10:54 AM
Threads.. Session var lost, App var ok Alvin Bruney ASP .Net 1 12-02-2003 01:56 AM
Invoking constructor : Foo(var) and Foo ins(var) Alex Vinokur C++ 4 09-24-2003 04:01 PM
does "struct_name var = { 0 }; " fill var with 0? Fred C++ 3 08-10-2003 09:44 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57