Code in HTML

  • Thread starter Joe via DotNetMonster.com
  • Start date
J

Joe via DotNetMonster.com

Hi,

Within the HTML if I try to put an if statement, I get an error:
BC30201: Expression expected

This is a simplified example:

<%# If StoreNumber = "1" Then %>

<b>Store1</b>

<%# EndIf %>

Thanks
 
P

Patrice

Use <% for code. <%# is for databidning.

As a side note this is a bit old style. I would recommend doing this in code
behing rather than mixing code and HTML as in the pre ASP.NET days...

Patrice
 
D

Dica

Patrice said:
Use <% for code. <%# is for databidning.

As a side note this is a bit old style. I would recommend doing this in code
behing rather than mixing code and HTML as in the pre ASP.NET days...

how do you control where the outputted html will show up on the aspx page if
you do this in your code behind? if, for instance, i have a search form and
a search button that executes some sql statements, and all this is handled
in the code behind, how would i go about response.writing the search results
to the bottom of the search page?
 
S

Steve

use a server control and write to that.
a label is rendered as a <span> tag I think, maybe a <div>, but either way,
that is one way to control where the output goes...
 
D

Dica

Steve said:
use a server control and write to that.
a label is rendered as a <span> tag I think, maybe a <div>, but either way,
that is one way to control where the output goes...
thanks


Dica said:
in
code

how do you control where the outputted html will show up on the aspx
page
 
G

Gordon Smith

Another way is to use the Literal control. It doesn't put any HTML tags
automatically - you can use it to inject HTML (or text or whatever) directly
into a specific location on your page.

HTH
 
B

Brock Allen

Well, the reason it's important is that the Literal holds view state and
for static HTML you don't want this unnecessary overhead.
 
K

Kevin Spencer

A LiteralControl holds ViewState?


A LiteralControl inherits System.Web.UI.Control, which means that it HAS
ViewState, but a LiteralControl doesn't HOLD ViewState. Note that the
ViewState property is protected.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
K

Kevin Spencer

Aha! Thanks for the clarification.

--

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top