<% and %> markers in a module

  • Thread starter Thread starter Pdarroch
  • Start date Start date
P

Pdarroch

Hello All

I am trying to upgrade my existing website from ASP to ASP.NET and I
have a file which included various functions common to several pages
in the site. While trying to convert this page I am having problems
because I the <% and %> markers appear to be invalid in ASP.NET; is
there any way of including HTML blocks in a module file as was
possible in ASP?

For instance, how can I use <% and %> markers to write the following
function:
Sub WriteMandatory()
%>
&nbsp;<span class="bodyred">
*
</span>&nbsp;
<%
End Sub

This is a simple example of the functions that I am trying to convert,
I do realise that this function can easily be converted to not use <%
and %> markers!

I am including this module (common.vb) in each page.

Thanks for any assistance

Paul
 
(e-mail address removed) (Pdarroch) wrote in
For instance, how can I use <% and %> markers to write the following
function:
Sub WriteMandatory()
%>
&nbsp;<span class="bodyred">
*
</span>&nbsp;
<%
End Sub

To write out text, use a literal control, and add the text to the literal
control. It's not a good idea to response.write text out anymore in .NET.
 
Hi

Just to clarify:
Is there no way to quickly convert large functions in modules with
dozens of lines of HTML contained within <% and %> markers to something
that is ASP.NET compatible, while preferably still maintaining the
formatting of the HTML in the output?

Thanks for quick response

PD
 
Hi

Just to clarify:
Is there no way to quickly convert large functions in modules with
dozens of lines of HTML contained within <% and %> markers to something
that is ASP.NET compatible, while preferably still maintaining the
formatting of the HTML in the output?

Thanks for quick response

PD
 
Is there no way to quickly convert large functions in modules with
dozens of lines of HTML contained within <% and %> markers to something
that is ASP.NET compatible, while preferably still maintaining the
formatting of the HTML in the output?

Not really... because the entire concept of outputting HTML in .NET has
radically changed.

Your best bet is to output the text into a literal control and then and the
literal control to the page via a placeholder or directly.
 
While you could certainly write a function like that using ASP, it wasn't
even a good idea then! Talk about mixing code and content! ASP.Net has been
built with the lessons of the past in mind, and therefore, will not allow
you to do such a terrible thing. In addition, ASP.Net is object-oriented, so
you'd better bone up on OOP. It's a whole different paradigm, and you'll
have a great deal of trouble if you try to make your procedural square box
code fit into that round hole.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
No. There are no short cuts. Only the hard way, and the harder way. The hard
way is to learn .Net, and OOP, and get with the program. The harder way is
to try a short cut.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Hi

I too dislike this approach to development (I can thank my predecessor
for this) and don't worry I am au fait with VB.NEt and the o-o paradigm,
but I am rather hazy on ASP.NET development practice. My reason for a
quick migration is so that I can rewrite the site properly while not
being limited in what pages can share session information, etc, etc.

How should one write out a table with a large amount of content in
ASP.Net when it is called from many locations? Should I use a User
Control, even though there is very little code in each of these
functions? For instance: if I was writing the readonly contents of a
shopping cart in three or four different pages, would I generally use a
user control to do this?

Thanks for your advice

PD
 
AFAIK no way. In ASP.NET you can't mix HTML and code (more precisely I
believe the exact change is that the code should be in a single block ie.
you can't begin a code block have some HTML and then terminate this same
block of code...)

If you want a quick and dirty port, your best bet is likely to transform
this to response.write statements before using a more appropriate .NET
feature...

Patrice
 
Hi Paul,

You would certainly use a Control. Whether to use a User Control or not, I
can't say, as I'm not familiar with your requirements.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Thanks very much Kevin and Patrice, I will try and go forward with this
approach.

Thanks again

PD
 
vb.net (jscript.net is much more compatiable) has different rules for use of
<% %>, largely incompatable with asp.

<% %> can only be used for inline code, and can contain no sub or function
declarations
<script runat=server> can only contain function and sub declarations, no
inline code.

this is all based on how the aspx is translated to a class module.

-- bruce (sqlwork.com)
 

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

Back
Top