当前位置:首页 > 网络编程 > WEB编程 > ASP.net >  利用MS AJAX 扩展服务器端控件2

 利用MS AJAX 扩展服务器端控件2

点击次数:31 次 发布日期:2008-11-26 11:06:11 作者:源代码网
源代码网推荐      六、下边是我们新添加的类的完整代码:
源代码网推荐  using System;
源代码网推荐  using System.Data;
源代码网推荐  using System.Configuration;
源代码网推荐  using System.Web;
源代码网推荐  using System.Web.Security;
源代码网推荐  using System.Web.UI;
源代码网推荐  using System.Web.UI.WebControls;
源代码网推荐  using System.Web.UI.WebControls.WebParts;
源代码网推荐  using System.Web.UI.HtmlControls;
源代码网推荐  using System.Collections.Generic;
源代码网推荐  
源代码网推荐  namespace TextBoxExtender
源代码网推荐  {
源代码网推荐   /**//// <summary>
源代码网推荐   /// SampleTextBox 的摘要说明
源代码网推荐   /// </summary>
源代码网推荐   public class SampleTextBox : TextBox, IScriptControl
源代码网推荐   {
源代码网推荐   private string _highlightCssClass;
源代码网推荐   private string _noHighlightCssClass;
源代码网推荐   private ScriptManager sm;
源代码网推荐  
源代码网推荐   public string HighlightCssClass
源代码网推荐   {
源代码网推荐   get { return _highlightCssClass; }
源代码网推荐   set { _highlightCssClass = value; }
源代码网推荐   }
源代码网推荐  
源代码网推荐   public string NoHighlightCssClass
源代码网推荐   {
源代码网推荐   get { return _noHighlightCssClass; }
源代码网推荐   set { _noHighlightCssClass = value; }
源代码网推荐   }
源代码网推荐  
源代码网推荐   protected override void OnPreRender(EventArgs e)
源代码网推荐   {
源代码网推荐   if (!this.DesignMode)
源代码网推荐   {
源代码网推荐   // Test for ScriptManager and register if it exists
源代码网推荐   sm = ScriptManager.GetCurrent(Page);
源代码网推荐  
源代码网推荐   if (sm == null)
源代码网推荐   throw new HttpException("A ScriptManager control must exist on the current page.");
源代码网推荐  
源代码网推荐   sm.RegisterScriptControl(this);
源代码网推荐   }
源代码网推荐  
源代码网推荐   base.OnPreRender(e);
源代码网推荐   }
源代码网推荐  
源代码网推荐   protected override void Render(HtmlTextWriter writer)
源代码网推荐   {
源代码网推荐   if (!this.DesignMode)
源代码网推荐   sm.RegisterScriptDescriptors(this);
源代码网推荐  
源代码网推荐   base.Render(writer);
源代码网推荐   }
源代码网推荐  
源代码网推荐   protected virtual IEnumerable<ScriptReference> GetScriptReferences()
源代码网推荐   {
源代码网推荐   ScriptReference reference = new ScriptReference();
源代码网推荐   reference.Path = ResolveClientUrl("SampleTextBox.js");
源代码网推荐  
源代码网推荐   return new ScriptReference[] { reference };
源代码网推荐   }
源代码网推荐  
源代码网推荐   protected virtual IEnumerable<ScriptDescriptor> GetScriptDescriptors()
源代码网推荐   {
源代码网推荐   ScriptControlDescriptor descriptor = new ScriptControlDescriptor("Samples.SampleTextBox", this.ClientID);
源代码网推荐   descriptor.AddProperty("highlightCssClass", this.HighlightCssClass);
源代码网推荐   descriptor.AddProperty("nohighlightCssClass", this.NoHighlightCssClass);
源代码网推荐  
源代码网推荐   return new ScriptDescriptor[] { descriptor };
源代码网推荐   }
源代码网推荐  
源代码网推荐   IEnumerable<ScriptReference> IScriptControl.GetScriptReferences()
源代码网推荐   {
源代码网推荐   return GetScriptReferences();
源代码网推荐   }
源代码网推荐  
源代码网推荐   IEnumerable<ScriptDescriptor> IScriptControl.GetScriptDescriptors()
源代码网推荐   {
源代码网推荐   return GetScriptDescriptors();
源代码网推荐   }
源代码网推荐   }
源代码网推荐  }
源代码网推荐  
源代码网推荐   七、创建客户端控件。为客户端控件注册一个命名空间,并实现各个属性和事件:
源代码网推荐  // 为控件注册命名控件
源代码网推荐  Type.registerNamespace("Samples");
源代码网推荐  
源代码网推荐  //
源代码网推荐  // 定义控件的属性
源代码网推荐  //
源代码网推荐  Samples.SampleTextBox = function(element) {
源代码网推荐   Samples.SampleTextBox.initializeBase(this, [element]);
源代码网推荐  
源代码网推荐   this._highlightCssClass = null;
源代码网推荐   this._nohighlightCssClass = null;
源代码网推荐  }
源代码网推荐  
源代码网推荐  //
源代码网推荐  // 为控件创建属性
源代码网推荐  //
源代码网推荐  
源代码网推荐  Samples.SampleTextBox.prototype = {
源代码网推荐  
源代码网推荐  
源代码网推荐   initialize : function() {
源代码网推荐   Samples.SampleTextBox.callBaseMethod(this, "initialize");
源代码网推荐  
源代码网推荐   this._onfocusHandler = Function.createDelegate(this, this._onFocus);
源代码网推荐   this._onblurHandler = Function.createDelegate(this, this._onBlur);
源代码网推荐  
源代码网推荐   $addHandlers(this.get_element(),
源代码网推荐   { "focus" : this._onFocus,
源代码网推荐   "blur" : this._onBlur },
源代码网推荐   this);
源代码网推荐  
源代码网推荐   this.get_element().className = this._nohighlightCssClass;
源代码网推荐   },
源代码网推荐  
源代码网推荐   dispose : function() {
源代码网推荐   $clearHandlers(this.get_element());
源代码网推荐  
源代码网推荐   Samples.SampleTextBox.callBaseMethod(this, "dispose");
源代码网推荐   },
源代码网推荐  
源代码网推荐   //
源代码网推荐   // 事件委托
源代码网推荐   //
源代码网推荐  
源代码网推荐   _onFocus : function(e) {
源代码网推荐   if (this.get_element() && !this.get_element().disabled) {
源代码网推荐   this.get_element().className = this._highlightCssClass;
源代码网推荐   }
源代码网推荐   },
源代码网推荐  
源代码网推荐   _onBlur : function(e) {
源代码网推荐   if (this.get_element() && !this.get_element().disabled) {
源代码网推荐   this.get_element().className = this._nohighlightCssClass;
源代码网推荐   }
源代码网推荐   },
源代码网推荐  
源代码网推荐  
源代码网推荐   //
源代码网推荐   // 控件属性
源代码网推荐   //
源代码网推荐  
源代码网推荐   get_highlightCssClass : function() {
源代码网推荐   return this._highlightCssClass;
源代码网推荐   },
源代码网推荐  
源代码网推荐   set_highlightCssClass : function(value) {
源代码网推荐   if (this._highlightCssClass !== value) {
源代码网推荐   this._highlightCssClass = value;
源代码网推荐   this.raisePropertyChanged("highlightCssClass");
源代码网推荐   }
源代码网推荐   },
源代码网推荐  
源代码网推荐   get_nohighlightCssClass : function() {
源代码网推荐   return this._nohighlightCssClass;
源代码网推荐   },
源代码网推荐  
源代码网推荐   set_nohighlightCssClass : function(value) {
源代码网推荐   if (this._nohighlightCssClass !== value) {
源代码网推荐   this._nohighlightCssClass = value;
源代码网推荐   this.raisePropertyChanged("nohighlightCssClass");
源代码网推荐   }
源代码网推荐   }
源代码网推荐  }
源代码网推荐  
源代码网推荐  // Optional descriptor for JSON serialization.
源代码网推荐  Samples.SampleTextBox.descriptor = {
源代码网推荐   properties: [ {name: "highlightCssClass", type: String},
源代码网推荐   {name: "nohighlightCssClass", type: String} ]
源代码网推荐  }
源代码网推荐  
源代码网推荐  // Register the class as a type that inherits from Sys.UI.Control.
源代码网推荐  Samples.SampleTextBox.registerClass("Samples.SampleTextBox", Sys.UI.Control);
源代码网推荐  
源代码网推荐  if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐  最后将如下代码复制到Default.aspx页面,用以测试空间:
源代码网推荐  <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
源代码网推荐  <%@ Register Namespace="TextBoxExtender" TagPrefix="sample" %>
源代码网推荐  
源代码网推荐  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
源代码网推荐  
源代码网推荐  <html xmlns="http://www.w3.org/1999/xhtml">
源代码网推荐  <head id="Head1" runat="server">
源代码网推荐   <title>ASP.NET AJAX Control Sample</title>
源代码网推荐   <style type="text/css">
源代码网推荐   .LowLight
源代码网推荐   {
源代码网推荐   background-color:#EEEEEE;
源代码网推荐   }
源代码网推荐  
源代码网推荐   .HighLight
源代码网推荐   {
源代码网推荐   background-color:Ivory;
源代码网推荐   }
源代码网推荐   </style>
源代码网推荐  </head>
源代码网推荐  <body>
源代码网推荐   <form id="form1" runat="server">
源代码网推荐   <asp:ScriptManager ID="ScriptManager1" runat="server" >
源代码网推荐   <Scripts>
源代码网推荐   <asp:ScriptReference Path="JScript.js" />
源代码网推荐   </Scripts>
源代码网推荐   </asp:ScriptManager>
源代码网推荐   <div>
源代码网推荐   <table border="0" cellpadding="2">
源代码网推荐   <tr>
源代码网推荐   <td><asp:Label runat="server" ID="Label1" AssociatedControlID="TextBox1">Name</asp:Label></td>
源代码网推荐   <td><sample:SampleTextBox ID="TextBox1" runat="server" NoHighlightCssClass="LowLight" HighlightCssClass="HighLight" /></td>
源代码网推荐   </tr>
源代码网推荐   <tr>
源代码网推荐   <td><asp:Label runat="server" ID="Label2" AssociatedControlID="TextBox2">Phone</asp:Label></td>
源代码网推荐   <td><sample:SampleTextBox ID="TextBox2" runat="server" NoHighlightCssClass="LowLight" HighlightCssClass="HighLight" /></td>
源代码网推荐   </tr>
源代码网推荐   <tr>
源代码网推荐   <td><asp:Label runat="server" ID="Label3" AssociatedControlID="TextBox3">E-mail</asp:Label></td>
源代码网推荐   <td><sample:SampleTextBox ID="TextBox3" runat="server" NoHighlightCssClass="LowLight" HighlightCssClass="HighLight" /></td>
源代码网推荐   </tr>
源代码网推荐   </table>
源代码网推荐  
源代码网推荐   <asp:Button runat="server" ID="Button1" Text="Submit Form" />
源代码网推荐   </div>
源代码网推荐   </form>
源代码网推荐  </body>
源代码网推荐  </html>
源代码网推荐  http://www.cnblogs.com/hblynn/archive/2007/01/29/633619.html
源代码网推荐    做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。
源代码网推荐


源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华