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

Expression Syntax: <%$ ... %> New in 2.0

ASP.NET 2.0 adds a new declarative expression syntax for substituting values into a page before the page is parsed. This is useful for substituting connection string values or application settings defined in a Web.config file for server control property values. It can also be used to substitute values from a resource file for locaization. More on connection string and resources expressions and expression handlers can be found in the Performing Data Access, Internationalizing Your Application and Extending ASP.NET sections.

<asp:SqlDataSource ID="SqlDataSource1" ConnectionString='<%$ connectionStrings:Pubs %>' 
runat="server" SelectCommand="sp_GetAuthors" /> <asp:Label ID="Label1" Text='<%$ Resources: ExchRate, ConvertLabel %>' runat="server"/>
posted @ 2006-03-27 17:25 Maxer`s Blog 阅读(98) 评论(1) 编辑

Object Tag Syntax: <object runat="server" />

Object tags enable page developers to declare and create instances of variables using a declarative, tag-based syntax. The following example demonstrates how the object tag can be used to create an instance of an ArrayList class.

<object id="items" class="System.Collections.ArrayList" runat="server"/>

The object will be created automatically at run time and can then be accessed through the ID "items".

<html>

   <script language="C#" runat=server>

      void Page_Load(Object sender, EventArgs e) {

         ArrayItems.Add("One");
         ArrayItems.Add("Two");
         ArrayItems.Add("Three");

         MyList.DataSource = ArrayItems;
         MyList.DataBind();
      }

   </script>

   <body>
   
   <object id="ArrayItems" class="System.Collections.ArrayList" runat=server/>

      <asp:datalist id="MyList" runat=server>

         <ItemTemplate>

            Here is a value: <%# Container.DataItem %>

         </ItemTemplate>

      </asp:datalist>

   </body>

</html>
posted @ 2006-03-27 17:20 Maxer`s Blog 阅读(154) 评论(0) 编辑

在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 @ 2006-03-27 16:49 Maxer`s Blog 阅读(113) 评论(1) 编辑
昵称:Maxer`s Blog
园龄:6年1个月
粉丝:0
关注:0

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

搜索

 
 

常用链接

随笔分类

随笔档案

Link

积分与排名

  • 积分 - 25956
  • 排名 - 4087

最新评论

阅读排行榜

评论排行榜

推荐排行榜