Programmatic production of HTML...

  • Thread starter Thread starter Paul Mason
  • Start date Start date
P

Paul Mason

Hi folks,

Just wondering how I can call a function in a code behind file from within
the body of the ASPX file.

The old ASP way was to use <%= MyFunction() %>, but that doesn't seem to
work anymore...Thus :

<body MS_POSITIONING="GridLayout">
<form id="frmAssessmentPrint" method="post" runat="server">
</form>
<% MyFunction() %>
</body>

I've tried a straight FunctionCall(), classname.FunctionCall() and
parent.FunctionCall().

I'm pretty certain that I've seen it somewhere in the help system or the
MSDN docs, but can't recall where. Is it possible at all from a code that's
in a seperate .VB code behind file??

To give you some background I'm writing a report where I'm parsing my data
into HTML. At the moment I'm feeding the output through the page_load event
using the reponse.write method, but it's putting the HTML before the <HTML>
tag. I've tried other events, but with no success. It's working OK like
this, but I suspect browsers other than IE will have problems with it.
Also, it's just generally useful to know...

Thanks in advance....Paul
 
Hi, Paul Mason,

How about adding a System.Web.UI.WebControls.Literal inside the form and
setting its Text property in the Page_Load handler? Is it limited that the
html you want to output should be outside the form?

Also, you can do it like this:

<body MS_POSITIONING="GridLayout">
<form id="frmAssessmentPrint" method="post" runat="server">
</form>
<%
Response.Write(MyFunction())
%>
</body>

Just add a semicolon (;) at the end of the line if you are using C#.
MyFunction() should be member of the class for the page. It can be also
static (in VB shared).

Greetings
Martin
 
You can still do this - <%= MyFunction%>, but you have to declare the
function in the codebehind as "Protected" in order to see it from the page.
 
Thanks. I didn't realise what the literal control was.

Thanks also to Rick for letting me know it had to be protected..

P
 
you can use dataBinding
int aspx file :
CustomerID :<%# CustomerID %>

in aspx.cs code file:
page_load()
{
this.DataBind();
}
 
Back
Top