Can you call asp function in asp.net?

G

Guest

Hi Guys,

Maybe you can help me out. Our company is interested to do .NET for the
first time. Our product is ASP based. We don't want to convert all our
existing stuff to .NET but create new applications in .NET. We created a lot
of APIs which is located in "inc" files that is in ASP. Is it possible to
call an ASP function in my ASPX page? For instance, in my ASPX :

<%@Page Language="VB" Explicit="True" %>
<!-- Foo.inc-->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body>
<table>
<tr>
<td><% Response.write(test("Hello"))%></td>
</tr>
</table>
</body>
</html>

-------------

Foo.inc file:


<%
function test(ByRef strValue as string)
' convert singl;e quote into a pair of single quotes
test=replace(strValue,"'","''")
end function

%>


When I run my code I get the following error:

Compiler Error Message: BC30451: Name 'test' is not declared.


Can you guys help me out? Thank you!
 
M

Marina

If the ASP code is 100% compative with the asp.net code model, then usre.

In this case, it is not. In asp.net, all functions need to be in <script
runat="server"> blocks. Only inline script can be in the <% %> blocks.
 
C

Cor Ligthert

Kat,

Some changes that I typed in this message, not checked

<script language="VB" runat=server>
function test(ByVal strValue as String) as String
' convert single quote into a pair of single quotes
return replace(strValue,"'","''")
End function
</script>

I hope this helps something?

Cor
 
G

Guest

Does that mean that I have to do that for every inc files? Our old product
that is written in ASP will also be using these functions also.

thanks in advance!
 
M

Marina

What it means, is that you can't use the inc files in both apps.

If you are going to rewrite them, you might as well eliminate them, and use
inheritance to achieve the same effect as you are porting your app to
asp.net.
 
C

Cor Ligthert

Kat,

I tried to show you the in my opinion nicest version.

<script language="VB" runat=server>
'this is nicer in ASPX and than all your subs and functions inside that.
It is not needed you can keep your old ASP style. Adviced is as far as I
know to upgrade this when busy with it. Doing that than it is easier to go
to code behind in future. Than you can by the way in the VBNet 2002/2003
versions not use your Inc pages anymore. (I don't know how that is in 2005)

function test(ByVal strValue as String) as String

'This is in my opinion your error. You did not write the return type "as
String".
'ByValue is in VBNet/CSharp almost forever more efficient than ByRef
'A reason to use ByRef can when you create a new object inside the function

Return replace(strValue,"'","''")
'This I find myself much nicer, however when you want what you had than that
is no problem at all.

I hope this helps?

Cor
 

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

Top