TRICK: ASP.NET methods with code blocks

T

TEN TOD PSA

you can trick ASP.NET into letting you declare methods with code blocks
(how anybody can survive without this i have no idea - in classic asp i
haven't written any html outside of a sub/method in 8 years - ASP.NET seems
to be going backwards in some respects)
(seems to me using Classic ASP but accessing the juicy .NET framework
features via COM Interop is a better choice than actually using ASP.NET)

in your aspx page do this:

(start)
<%
}
void RenderHTML(System.Web.UI.HtmlTextWriter __output) {
%><%="what ever you want"%><%
(end)

explanation follows:

(inside a code block)
<%
(close the render method with a brace)
}
(declare a new method which takes the hidden output object)
void RenderHTML(System.Web.UI.HtmlTextWriter __output) {
(use a codeblock inside the method)
%><%="what ever you want"%><%
(omit the closing brace - asp will put it in for you thinking it is closing
the render method)
(end)

you can call your new method as follows:

RenderHTML(__output);
 
B

Bob Barrows [MVP]

TEN said:
you can trick ASP.NET

There was no way for you to know it, but this is a classic asp newsgroup.
While you may be lucky enough to find a dotnet-knowledgeable person here who
can answer your question, you can eliminate the luck factor by posting your
question to a group where those dotnet-knowledgeable people hang out. I
suggest microsoft.public.dotnet.framework.aspnet.
 

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

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top