Programmatic production of HTML...

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
 
M

Martin Dechev

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
 
R

Rick Spiewak

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.
 
P

Paul Mason

Thanks. I didn't realise what the literal control was.

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

P
 
C

coollzh

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

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

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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top