当前位置: 首页 > 图文教程 > 网络编程 > ASP > asp+语法介绍(五)----asp+的服务器端编程控件篇

ASP
ASP调用ORACLE存储过程并返回结果集
用ASP实现网页BBS
关于Global.asa文件的深入研究与session变量失效提示的具体方法
简易ASP+注册系统
防护手册:如何防止ASP木马在服务器上运行
用Visual Basic实现多画面播放功能之二
如何增强ASP程序性能(1)
如何增强ASP程序性能(2)
如何增强ASP程序性能(3)
ASP备份数据库
二十八条改善 ASP 性能和外观的技巧
在Form域中Post大于100K的数据
如何使用ASP制作模似动态生长的表单?
Microsoft IIS 真的如此「不安全」吗?(1)
Microsoft IIS 真的如此「不安全」吗?(2)
Microsoft IIS 真的如此「不安全」吗?(3)
Microsoft IIS 真的如此「不安全」吗?(4)
Microsoft IIS 真的如此「不安全」吗?(5)
关于页面和代码分离
ServerVariables 对路径的操作

ASP 中的 asp+语法介绍(五)----asp+的服务器端编程控件篇


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 29 ::
收藏到网摘: n/a

       使用定制的服务器控件
  在asp+中提供了45个已经做好了的服务器控件,我们可以将他们象黑盒子一样的使用。除此以外,开发者还可以使用任何第三方开发的服务器控件
  在下面的例子中,我们要用到一个通过<acme:calendar runat=server>标签声明的组件,请注意,在文件的第一行必须使用<% Register %> 来声明 "Acme Xml "标签的的前缀"Acme".在asp+ 文件中,将会使用这个命名的服务器控件的类的实例。
  <%@ Register TagPrefix="Acme" Namespace="Acme" %>
  
  <html>
   <head>
   <link rel="stylesheet"href="intro.css">
   </head>
  
   <script language="VB" runat=server>
  
   Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
   Message.Text = "Hi " & Name.Text & ", you selected: " & Category.SelectedItem.Text & " on: " & MyCal.Date
   End Sub
  
   </script>
  
   <body>
  
   <center>
  
   <form action="intro7.aspx" method="post" runat="server">
  
   <asp:adrotator AdvertisementFile="ads.xml" BorderColor="black" BorderWidth=1 runat="server"/>
  
   <h3> Name: <asp:textbox id="Name" runat="server"/>
  
   Category: <asp:dropdownlist id="Category" runat=server>
   <asp:listitem >psychology</asp:listitem>
   <asp:listitem >business</asp:listitem>
   <asp:listitem >popular_comp</asp:listitem>
   </asp:dropdownlist>
  
   <asp:button type=submit text="Lookup" OnClick="SubmitBtn_Click" runat="server"/>
  
   <p>
  
   <Acme:Calendar id="MyCal" runat=server/>
  
   <p>
  
   <asp:label id="Message" runat="server"/>
  
   </form>
  
   </center>
  
   </body>
  </html>
  
  声明Acme 的 文件
  using System;
  using System.Web;
  using System.Web.UI;
  using System.Collections;
  
  namespace Acme
  {
   public class Calendar : Control, IPostBackEventHandler, IPostBackDataHandler
   {
   private String[] monthNames = new String[12];
   private DateTime currentDate = DateTime.Now;
   private String backColor = "#dcdcdc";
   private String foreColor = "#eeeeee";
  
   protected override void Init()
   {
   // Todo: We should remove the need to call this
   Page.RegisterRequiresPostBack(this);
   Page.RegisterPostBackScript();
  
   currentDate = DateTime.Now;
  
   // Todo: Hack needed because COOL doesn't support array initializers yet
   monthNames[0] = "January";
   monthNames[1] = "February";
   monthNames[2] = "March";
   monthNames[3] = "April";
   monthNames[4] = "May";
   monthNames[5] = "June";
   monthNames[6] = "July";
   monthNames[7] = "August";
   monthNames[8] = "Se