ASP.NET 2.0学习笔记之Code Directory

在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中申明一个用于放置其他语言的子目录.
Snap1.jpg

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

cptrk.ashx?id=2db342cd-96f2-4acc-baa0-450b56b17757

转载于:https://www.cnblogs.com/Maxer/archive/2006/03/27/360196.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值