473,385 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Conditional html blocks

In scripting languages such as PHP and ColdFusion, it is easy to
conditionally include a block of html using something like
(pseudocode):

<if x=true>
This is some <b>random html<b>
that gets displayed if x is true and not otherwise
</if>

I've been coding using c# and asp.net and find it impossible to do the
same thing on asp.net pages. I don't need the html block parsed, so 2
passes aren't needed (although that would be nice).

Nov 19 '05 #1
2 3321
If you are having trouble doing this with asp.net, then I don't believe you full understand how asp.net controls work. For instance, to accomplish your example you could do the following.

Put all the random html you want inside an <asp:placeholder> control

Then from a script block, you can do this

myPlaceHolder.Visible = x;

(if x is true, so will the contents of the placeholder)

--Michael

"Richard Frenkel" <ne*******@frenkelfamily.org> wrote in message news:11**********************@c13g2000cwb.googlegr oups.com...
In scripting languages such as PHP and ColdFusion, it is easy to
conditionally include a block of html using something like
(pseudocode):

<if x=true>
This is some <b>random html<b>
that gets displayed if x is true and not otherwise
</if>

I've been coding using c# and asp.net and find it impossible to do the
same thing on asp.net pages. I don't need the html block parsed, so 2
passes aren't needed (although that would be nice).

Nov 19 '05 #2
You can simply place the text in a literal or placeholder and switch the
visibility of it, pseudocode:

<asp:plaholder id="plc" runat="server">
this is some <b>random html</b>
that gets displayed if x is true and not otherwise
</asp:plaholder >

Sub Page_Load
plc.Visible = (x = true)
end sub

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Richard Frenkel" <ne*******@frenkelfamily.org> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
In scripting languages such as PHP and ColdFusion, it is easy to
conditionally include a block of html using something like
(pseudocode):

<if x=true>
This is some <b>random html<b>
that gets displayed if x is true and not otherwise
</if>

I've been coding using c# and asp.net and find it impossible to do the
same thing on asp.net pages. I don't need the html block parsed, so 2
passes aren't needed (although that would be nice).

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bruce | last post by:
Which of the popular templating systems (e.g. PHLib, FastTemplate, Smarty) allow you to setup conditions in your templates, for example: <-- IF Variable=value --> this HTML <-- ELSEIF...
11
by: Steven T. Hatton | last post by:
I've made no secret of the fact that I really dislike the C preprocessor in C++. No aspect of the language has caused me more trouble. No aspect of the language has cause more code I've read to be...
28
by: Benjamin Niemann | last post by:
Hello, I've been just investigating IE conditional comments - hiding things from non-IE/Win browsers is easy, but I wanted to know, if it's possible to hide code from IE/Win browsers. I found...
8
by: Dimitri Furman | last post by:
Given: Access 2002/2003 A subform in datasheet or continuous view, placed on a tab page (this last may or may not matter) Conditional formatting applied to some controls on the subform - format...
10
by: John Smith | last post by:
After reading C# documentation the Conditional attribute seemed the way to go, but after inspecting the IL it seems those methods are still there and I imagine the CLR removes them. Using #if DEBUG...
2
by: estafford | last post by:
I am having trouble writing a conditional block using ASP.NET and C#. I am trying to do something like this: 1. if page is PostBack - transfer to another page 2. if not postback - connect...
10
by: Dave | last post by:
I'm a C++ programmer of many years, trying to get my feet wet in C#. I have a question about conditional compilation. In C++, I would sometimes define a constant in an include file, and then...
12
by: code break | last post by:
Hi all, Please can any one tell me the importance of below code... #if 0 /*what is use of this macro conditional.since this is every time false .*/ stmt1 ; #else
6
by: patrick j | last post by:
Hi I've been testing out the "Conditional Comment" for IE. This is because for my web-site I want to have two style sheets, one for IE 6 and one for other browsers. Thus I hope to have my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.