asp页面中的函数失败

时间:2013-05-08 20:54:57

标签: asp.net

我对asp.net有点问题。我正在尝试将函数直接编程到ASP页面中,但它失败了。

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication2.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
    // My function 
    Sub print()
        Response.Write("example")
    End Sub%>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>

这是一个错误:

Línea 242:            
Línea 243:            #End ExternalSource
Línea 244:            Me.__PageInspector_EndRenderTracing(New Object() {__w})
Línea 245:        End Sub
Línea 246:        

任何人都可以帮助我吗?提前谢谢!

1 个答案:

答案 0 :(得分:4)

试试这个

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication2.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">  
    // My function 
    Sub print()
        Response.Write("example")
    End Sub
</script>  

您错过了使用script代码

包装代码

另请注意,您并未在任何地方致电print,因此无法执行任何操作。