473,406 Members | 2,620 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,406 software developers and data experts.

If Statement in HTML

I am new to ASP.NET I have worked many years in Coldfusion. I am having a
problem finding out how to put an IF Statement into the HTML. How do I do
this in ASP.NET?

Thanks for any help you can give!!!

For example in CF if I want to put an IF Statement I would do something link
this.

<cfif khst.recordcount GT 0>
<tr>
<td class="text">Please Select a City </td>
<td width="181" height="15" align="left"
class="text"><cfselect name="city" query="khcity" value="city"
display="city" queryPosition="below" selected="#city#"
onChange="this.form.submit()">
<option value="PS" selected="selected">Please
Select a City</option>
</cfselect></td>
<cfif city NEQ "Please Select a City">
<td colspan="2" align="left" class="text">Number
of Matches <cfoutput>#khcityc.recordcount#</cfoutput></td>
<cfelse>
</cfif>
</tr>
</cfif>
Aug 22 '06 #1
8 2833
The new approach is to just use a DataGrid or GridView control.
There are also Table controls and Repeater controls & such if you need more
granularity.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"Rick" <ri**@di-wave.comwrote in message
news:O4**************@TK2MSFTNGP05.phx.gbl...
>I am new to ASP.NET I have worked many years in Coldfusion. I am having a
problem finding out how to put an IF Statement into the HTML. How do I do
this in ASP.NET?

Thanks for any help you can give!!!

For example in CF if I want to put an IF Statement I would do something
link this.

<cfif khst.recordcount GT 0>
<tr>
<td class="text">Please Select a City </td>
<td width="181" height="15" align="left"
class="text"><cfselect name="city" query="khcity" value="city"
display="city" queryPosition="below" selected="#city#"
onChange="this.form.submit()">
<option value="PS" selected="selected">Please
Select a City</option>
</cfselect></td>
<cfif city NEQ "Please Select a City">
<td colspan="2" align="left"
class="text">Number of Matches
<cfoutput>#khcityc.recordcount#</cfoutput></td>
<cfelse>
</cfif>
</tr>
</cfif>

Aug 22 '06 #2
Same grammar we did in CFML, ASP and PHP but different syntax unique to the
scripting language(s) and while nested conditional logic is still supported
in ASP.NET ala <% ... %most of us dropped that like a bad habit when we
discovered code-behind, web controls, and what are called user controls,
e.g. extensible #include files. Note there are also a number of expression
code blocks that remain in wide use as well as some new expressions for data
binding <%# ... %>.

I'd recommend mastering the page life cycle and the use of web and user
controls. The sooner you learn you are no longer scripting the sooner you
will be able to think using OOP designs and patterns.

Finally, HTML elements are usually referred to as HTML controls in ASP.NET
and are parsed the same way HTML elements are only much later in the page
life cycle. HTML controls can function as web controls when the attribute
pair runat="server" is declared which is why one must assume they are
usually referred to as HTML controls rather than HTML elements.

Being a convert I hope you had sufficient insight to choose C#.

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W

"Rick" <ri**@di-wave.comwrote in message
news:O4**************@TK2MSFTNGP05.phx.gbl...
>I am new to ASP.NET I have worked many years in Coldfusion. I am having a
problem finding out how to put an IF Statement into the HTML. How do I do
this in ASP.NET?

Thanks for any help you can give!!!

For example in CF if I want to put an IF Statement I would do something
link this.

<cfif khst.recordcount GT 0>
<tr>
<td class="text">Please Select a City </td>
<td width="181" height="15" align="left"
class="text"><cfselect name="city" query="khcity" value="city"
display="city" queryPosition="below" selected="#city#"
onChange="this.form.submit()">
<option value="PS" selected="selected">Please
Select a City</option>
</cfselect></td>
<cfif city NEQ "Please Select a City">
<td colspan="2" align="left"
class="text">Number of Matches
<cfoutput>#khcityc.recordcount#</cfoutput></td>
<cfelse>
</cfif>
</tr>
</cfif>

Aug 22 '06 #3
I am not quite following you. Let's say I have a DataCombo control on a
page. Now depending on the choices the client chooses I may want to display
that DataCombo or not. Are you saying this is not done with an IF statement
any longer? Would I use something like the visible = True command or
something like that?

"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.comwro te in message
news:eF**************@TK2MSFTNGP04.phx.gbl...
Same grammar we did in CFML, ASP and PHP but different syntax unique to
the scripting language(s) and while nested conditional logic is still
supported in ASP.NET ala <% ... %most of us dropped that like a bad
habit when we discovered code-behind, web controls, and what are called
user controls, e.g. extensible #include files. Note there are also a
number of expression code blocks that remain in wide use as well as some
new expressions for data binding <%# ... %>.

I'd recommend mastering the page life cycle and the use of web and user
controls. The sooner you learn you are no longer scripting the sooner you
will be able to think using OOP designs and patterns.

Finally, HTML elements are usually referred to as HTML controls in ASP.NET
and are parsed the same way HTML elements are only much later in the page
life cycle. HTML controls can function as web controls when the attribute
pair runat="server" is declared which is why one must assume they are
usually referred to as HTML controls rather than HTML elements.

Being a convert I hope you had sufficient insight to choose C#.

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W

"Rick" <ri**@di-wave.comwrote in message
news:O4**************@TK2MSFTNGP05.phx.gbl...
>>I am new to ASP.NET I have worked many years in Coldfusion. I am having a
problem finding out how to put an IF Statement into the HTML. How do I do
this in ASP.NET?

Thanks for any help you can give!!!

For example in CF if I want to put an IF Statement I would do something
link this.

<cfif khst.recordcount GT 0>
<tr>
<td class="text">Please Select a City </td>
<td width="181" height="15" align="left"
class="text"><cfselect name="city" query="khcity" value="city"
display="city" queryPosition="below" selected="#city#"
onChange="this.form.submit()">
<option value="PS" selected="selected">Please
Select a City</option>
</cfselect></td>
<cfif city NEQ "Please Select a City">
<td colspan="2" align="left"
class="text">Number of Matches
<cfoutput>#khcityc.recordcount#</cfoutput></td>
<cfelse>
</cfif>
</tr>
</cfif>


Aug 22 '06 #4
Hi,

Rick wrote:
I am not quite following you. Let's say I have a DataCombo control on a
page. Now depending on the choices the client chooses I may want to display
that DataCombo or not. Are you saying this is not done with an IF statement
any longer? Would I use something like the visible = True command or
something like that?
What he means is that you still can use conditional statements in the
ASPX page if you want (with the <% %syntax, à la "old" ASP), but it's
not state of the art anymore.

You have different ways to choose to display a control or not.

- If you render the HTML code directly using a HtmlTextWriter (for
example in Custom Controls), then you can choose to render the HTML code
or not.
- If you use a Page of a User control, you can choose to add the said
control to the Controls collection or not.
- Finally, you can choose to always add the control to the Controls
collection, and use Visible to display it or not.

I am sure there are other ways too.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 22 '06 #5
"Laurent Bugnion" <ga*********@bluewin.chwrote in message
news:et****************@TK2MSFTNGP06.phx.gbl...
Hi,

Rick wrote:
>I am not quite following you. Let's say I have a DataCombo control on a
page. Now depending on the choices the client chooses I may want to
display that DataCombo or not. Are you saying this is not done with an IF
statement any longer? Would I use something like the visible = True
command or something like that?

What he means is that you still can use conditional statements in the ASPX
page if you want (with the <% %syntax, à la "old" ASP), but it's not
state of the art anymore.

You have different ways to choose to display a control or not.

- If you render the HTML code directly using a HtmlTextWriter (for example
in Custom Controls), then you can choose to render the HTML code or not.
- If you use a Page of a User control, you can choose to add the said
control to the Controls collection or not.
- Finally, you can choose to always add the control to the Controls
collection, and use Visible to display it or not.

For clarity, from all these different ways, the last one will be used in 99%
of the cases.

--

Riki
Aug 22 '06 #6
Hello Rick,

I agree with Laurent, in ASP.NET you have many choices to finish the work,
however, we recommend that you make use of the ASP.NET server controls and
use control model and postback events to manipulate control states.

For your scenario, you can use the DropDownList control to display list
items and use the dropdownlist control's "SelectedIndexChanged" event to
change other control's states/properties:

#DropDownList Class
http://msdn2.microsoft.com/en-us/lib...rols.dropdownl
ist.aspx
for example, here is a test page which contains two dropdownlist, when the
first dropdownlist's selected item has changed, the second dropdownlist
will be hidden or showed according to the first list's selected value:(I've
also attached the complete page's aspx and cs file in this message, you can
get it if you're using Outlook express to visit the newsgroup):

==============aspx page===================

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" /><br />
<br />

ASP.NET server control means:<br />
<hr />
&nbsp;<asp:DropDownList ID="lstServer1" runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="lstServer1_SelectedIndexCh anged">
<asp:ListItem>show</asp:ListItem>
<asp:ListItem>hide</asp:ListItem>

</asp:DropDownList>
<asp:DropDownList ID="lstServer2" runat="server">
<asp:ListItem>aaa</asp:ListItem>
<asp:ListItem>bbb</asp:ListItem>
<asp:ListItem>ccc</asp:ListItem>
</asp:DropDownList>
<br />
</div>
</form>
</body>
</html>

======code behind (c#) ====================
public partial class databind_ListControlPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void lstServer1_SelectedIndexChanged(object sender, EventArgs
e)
{
if (lstServer1.SelectedIndex == 0)
{
lstServer2.Visible = true;
}
else
{
lstServer2.Visible = false;
}
}
}

==========================
Please feel free to let me know if there is anything unclear or if there is
anyother information you wonder.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Aug 22 '06 #7
Thanks everyone for all your help it is coming into focus slowly....

Rick

"Rick" <ri**@di-wave.comwrote in message
news:O4**************@TK2MSFTNGP05.phx.gbl...
>I am new to ASP.NET I have worked many years in Coldfusion. I am having a
problem finding out how to put an IF Statement into the HTML. How do I do
this in ASP.NET?

Thanks for any help you can give!!!

For example in CF if I want to put an IF Statement I would do something
link this.

<cfif khst.recordcount GT 0>
<tr>
<td class="text">Please Select a City </td>
<td width="181" height="15" align="left"
class="text"><cfselect name="city" query="khcity" value="city"
display="city" queryPosition="below" selected="#city#"
onChange="this.form.submit()">
<option value="PS" selected="selected">Please
Select a City</option>
</cfselect></td>
<cfif city NEQ "Please Select a City">
<td colspan="2" align="left"
class="text">Number of Matches
<cfoutput>#khcityc.recordcount#</cfoutput></td>
<cfelse>
</cfif>
</tr>
</cfif>

Aug 22 '06 #8
It will come together much easier and perhaps faster if you take what I
suggested more seriously than simply picking up what sounds like an
immediate tip or two. That is all fine and well but will still leave you
coding in a shroud of mystery of how ASP.NET actually works until you find
and study all you can about the page life cycle, the control life cycle and
how the page contents are compiled. Especially if you intend to use Master
Pages.
<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W

"Rick" <ri**@di-wave.comwrote in message
news:ut**************@TK2MSFTNGP02.phx.gbl...
Thanks everyone for all your help it is coming into focus slowly....

Rick

"Rick" <ri**@di-wave.comwrote in message
news:O4**************@TK2MSFTNGP05.phx.gbl...
>>I am new to ASP.NET I have worked many years in Coldfusion. I am having a
problem finding out how to put an IF Statement into the HTML. How do I do
this in ASP.NET?

Thanks for any help you can give!!!

For example in CF if I want to put an IF Statement I would do something
link this.

<cfif khst.recordcount GT 0>
<tr>
<td class="text">Please Select a City </td>
<td width="181" height="15" align="left"
class="text"><cfselect name="city" query="khcity" value="city"
display="city" queryPosition="below" selected="#city#"
onChange="this.form.submit()">
<option value="PS" selected="selected">Please
Select a City</option>
</cfselect></td>
<cfif city NEQ "Please Select a City">
<td colspan="2" align="left"
class="text">Number of Matches
<cfoutput>#khcityc.recordcount#</cfoutput></td>
<cfelse>
</cfif>
</tr>
</cfif>


Aug 22 '06 #9

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

Similar topics

1
by: dmiller23462 | last post by:
Hey guys.... I put an error-handling in my page and have it posted at the complete end of the code, see below(when people were putting in 's I was getting the delimiter errors). Great, I...
8
by: CMAR | last post by:
I create my website using Front Page 2000. I notice that none of my pages have a DocType statement at the top. I have read that if you want IE6 to use "Standards mode" rather than the "Quirks...
6
by: tshad | last post by:
In my User control, I tried to do this: *************************************************************************** <Script runat="server"> Public ClientName As String = "<!-- #include file =...
35
by: Thierry Loiseau | last post by:
Hello all, and Happy end year 2005 ! Well, I would like to obtain a list of all JavaScript var statement, With "for...in" perharps ? That is bellow my recent test here, but the problem is...
37
by: Steven Bethard | last post by:
The PEP below should be mostly self explanatory. I'll try to keep the most updated versions available at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
18
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
28
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions!...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
1
by: Phil Latio | last post by:
Can anyone tell me why:- class=\"$this->styleclass\" statement in the function generateHTML() (which is at very bottom) fails to pass the value "error" meaning I can't use the style class I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.