在ASP.NET中我们如何使用 Class 而不是组件

王朝asp·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

导 读:在 代码的最上方,用类似下面的代码:

<%@ Assembly src="test.cs" %>

<%@ Assembly src="test.vb" %>

告诉编译器 把 文件中包含的 Class 编译到asp.net 页面中,以便对它进行调用

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

/*

豆腐制作 都是精品

http://www.asp888.net 豆腐技术站

如果您转贴 本文 请 保留版权信息

更多文章 都在 豆腐技术站

*/

asp+ 中我们有办法使用 预编译(pre-release)的代码 而不是 已经编译好的 二进制代码(build-in) 的组件

下面我们来看看一个例子

你可能会用到类似下面的代码:

<%@ Assembly src="test.cs" %> // Compile C# class

<%@ Assembly src="test.vb" %> // Compile VB class

在 代码的最上方 我们使用这样的 代码告诉编译器 把 文件中包含的 Class 编译到asp+ 的页面中

test.cs:

public class MyClass {

public string SaySomething() {

return "豆腐制作 都是精品";

}

}

test.vb:

public class test

readonly Property SaySomething() as string

get

SaySomething="豆腐制作 都是精品"

end get

end Property

end class

test.aspx:

<%@ Assembly Src="test.vb" %>

<html>

<script language="VB" runat=server>

Sub Page_Load(Sender as Object, E as EventArgs)

Dim Temp as New test

lblMsg.Text = temp.SaySomething()

End Sub

</script>

<body>

<asp:label id="lblMsg" runat=server/>

</body>

</html>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航