Maxer 's Blog
态度决定一切,理想成就未来!
posts - 43,  comments - 18,  trackbacks - 2

在ASP.NET 2.0中可以同是调用VB,C#中的类.
By default, the App_Code directory can only contain files of the same language. However, you may partition the App_Code directory into subdirectories (each containing files of the same language) in order to contain multiple languages under the App_Code directory. To do this, you need to register each subdirectory in the Web.config file for the application.
可以在WEB.CONFIG中申明一个用于放置其他语言的子目录.

web.config
-----------------------------------------------------------------------------------------------------------
<configuration>
  <system.web>
    <compilation>
      <codeSubDirectories>
        <add directoryName="Subdirectory"/>  // Your custom dirctionory which to contain the deferenet lanuage class such as vb
      </codeSubDirectories>
    </compilation>
  </system.web>
</configuration>
-----------------------------------------------------------------------------------------------------------

customClass.cs
-----------------------------------------------------------------------------------------------------------
using System;

public class CustomClass
{
    public String GetMessage(String input) {
        return "Hello " + input;
    }
}
-----------------------------------------------------------------------------------------------------------

SubDirectory/customClass.vb
-----------------------------------------------------------------------------------------------------------
Imports Microsoft.VisualBasic

Public Class CustomClass2

    Public Function GetMessage(ByVal name As String) As String
        Return "Hello from VB " & name
    End Function

End Class
-----------------------------------------------------------------------------------------------------------

page.aspx
-----------------------------------------------------------------------------------------------------------
<%
@ page language="C#" %>


<script runat="server">

  void Button1_Click(object sender, EventArgs e)
  {
    CustomClass c = new CustomClass();
    Label1.Text = c.GetMessage(TextBox1.Text);

    CustomClass2 c2 = new CustomClass2();
    Label2.Text = c2.GetMessage(TextBox1.Text);
  }
</script>

<html>
<head>
    <title>ASP.NET Inline Pages</title>
</head>
<body>
    <form id="Form1" runat="server">
      <h1>Welcome to ASP.NET 2.0!</h1>
      <b>Enter Your Name:</b>
      <asp:TextBox ID="TextBox1" Runat="server"/>
      <asp:Button ID="Button1" Text="Click Me" OnClick="Button1_Click" Runat="server"/>
      <br />
      <br />
      <asp:Label ID="Label1" Runat="server" />
      <br />
      <asp:Label ID="Label2" Runat="server" />
    </form>
</body>
</html>
-----------------------------------------------------------------------------------------------------------

posted on 2006-03-27 16:49 Maxer`s Blog 阅读(113) 评论(1) 编辑 收藏

FeedBack:
2007-10-17 08:34 | 厦门网站建设[未注册用户]
恩.好文章.谢谢
 回复 引用   
昵称:Maxer`s Blog
园龄:6年1个月
粉丝:0
关注:0

<2006年3月>
2627281234
567891011
12131415161718
19202122232425
2627282930311
2345678

搜索

 
 

常用链接

随笔分类

随笔档案

Link

积分与排名

  • 积分 - 25956
  • 排名 - 4089

最新评论

阅读排行榜

评论排行榜

推荐排行榜