基于ASP.NET的JQueryUI控件开发(1) - JQueryScriptManager

前面基本实现了ASP.NET MVC的 JQueryUI控件,现在准备写一套ASP.NET的JQueryUI控件开发,

今天先写一个JQueryScriptManager的实现.(基于ASP.NET MVC的基础上进行的开发,最终写成的控件即可以应用于ASP.NET也可以应用于ASP.NET MVC).

先上图:

三个引入使用的是Bool类型属性,

皮肤使用枚举类型,此类型在前面已定义:

Code:
  1. public enum JQSkin   
  2. {   
  3.     blitzer,   
  4.     humanity,   
  5.     redmond,   
  6.     smoothness,   
  7.     sunny,   
  8.     ui_darkness,   
  9.     ui_lightness,   
  10.     start,   
  11.     overcast,   
  12.     le_frog,   
  13.     flick,   
  14.     pepper_grinder           
  15. }  

一、实现 控件设计时显示JQuery Script Manager -htt://www.hahaman.cn效果

Code:
  1. public class JQueryManager:Control  
Code:
  1. protected override void Render(HtmlTextWriter writer)   
  2. {   
  3.     base.Render(writer);   
  4.     if (base.DesignMode)   
  5.     {   
  6.         writer.Write("<button style='width:270px; text-align:left;font-size:12px'><b>JQuery Script Manager</b>-<a href='http://www.hahaman.cn'>http://www.hahaman.cn</a></button>");   
  7.     }   
  8. }  

即可实现,

二、设置功能实现:

首先需要实现JQuery Script Manager 类中的属性

Code:
  1.  //属性定义   
  2.  public bool JQueryJs { getset; }   
  3.  public bool JQueryUIJs { getset; }   
  4.  public JQSkin Skins { getset; }   
  5.  public bool JQueryLngZh_CN { getset; }   
  6.   
  7.   
  8.  //初始化   
  9.  public JQueryManager()   
  10.  {   
  11.      this.JQueryJs = true;   
  12.      this.JQueryUIJs = true;   
  13.      this.JQueryLngZh_CN = true;   
  14.      this.Skins = JQSkin.smoothness;   
  15.  }   
  16.   
  17.  //加载处理   
  18.  protected override void OnLoad(EventArgs e)   
  19.  {   
  20.      if (JQueryJs)   
  21.          this.Page.ClientScript.RegisterClientScriptInclude("jquery", Page.ClientScript.GetWebResourceUrl(typeof(JQueryUIExt), "Hahaman.Mvc.UI.jquery-1.4.2.min.js"));   
  22.      if (JQueryUIJs)   
  23.      {   
  24.          this.Page.ClientScript.RegisterClientScriptInclude("jqueryui", Page.ClientScript.GetWebResourceUrl(typeof(JQueryUIExt), "Hahaman.Mvc.UI.jquery-ui-1.8.2.custom.min.js"));   
  25.          string skin = Skins.ToString();   
  26.          Literal lit = new Literal();   
  27.          lit.Text = "/n<link href=/"" + Page.ClientScript.GetWebResourceUrl(typeof(JQueryUIExt), "Hahaman.Mvc.UI." + skin + ".jquery-ui-1.8.2.custom.css") + "/" rel=/"stylesheet/" type=/"text/css/" />";   
  28.          this.Page.Header.Controls.Add(lit);   
  29.      }   
  30.      if (JQueryLngZh_CN)   
  31.          this.Page.ClientScript.RegisterClientScriptInclude("jquerylng", Page.ClientScript.GetWebResourceUrl(typeof(JQueryUIExt), "Hahaman.Mvc.UI.jquery.ui.datepicker-zh-CN.js"));   
  32. }  

实现设计类:JQeryManagerDesigner 

Code:
  1. public class JQeryManagerDesigner : ControlDesigner,IComponent   
  2. {   
  3.     public JQeryManagerDesigner()   
  4.         : base()   
  5.     {   
  6.               
  7.     }   
  8.     public override DesignerActionListCollection ActionLists   
  9.     {   
  10.         get  
  11.         {   
  12.             DesignerActionListCollection actionList    
  13.                 = new DesignerActionListCollection();   
  14.             actionList.Add(new JQueryManagerActionList(base.Component));   
  15.             return actionList;   
  16.         }   
  17.     }  
  18.  
  19.     #region IComponent 成员   
  20.   
  21.     public event EventHandler Disposed;   
  22.   
  23.     public ISite Site   
  24.     {   
  25.         get  
  26.         {   
  27.             throw new NotImplementedException();   
  28.         }   
  29.         set  
  30.         {   
  31.             throw new NotImplementedException();   
  32.         }   
  33.     }  
  34.  
  35.     #endregion   
  36. }  

ActionList类:JQueryManagerActionList

Code:
  1. public class JQueryManagerActionList : DesignerActionList   
  2. {   
  3.     IComponent _parent;   
  4.     public JQueryManagerActionList(IComponent c)   
  5.         : base(c)   
  6.     {   
  7.         _parent = c;   
  8.     }   
  9.     private DesignerActionItemCollection items;   
  10.     public override DesignerActionItemCollection GetSortedActionItems()   
  11.     {   
  12.         if (items == null)   
  13.         {   
  14.             items = new DesignerActionItemCollection();   
  15.             items.Add(new DesignerActionHeaderItem("JQuery Script设置"));   
  16.             items.Add(new DesignerActionPropertyItem("JQueryJs""引入JQuery.js"));   
  17.             items.Add(new DesignerActionPropertyItem("JQueryUIJs""引入JQuery.UI.js"));   
  18.             items.Add(new DesignerActionPropertyItem("JQueryLngZh_CN","引入JQuery中文语言包"));   
  19.             items.Add(new DesignerActionPropertyItem("Skins""皮肤"));   
  20.         }   
  21.         return items;   
  22.     }   
  23.   
  24.     private JQueryManager JQueryManager   
  25.     {   
  26.         get  
  27.         {   
  28.             return (JQueryManager)_parent;   
  29.         }   
  30.     }   
  31.     public bool JQueryJs {   
  32.         get  
  33.         {   
  34.             return JQueryManager.JQueryJs;   
  35.         }   
  36.         set  
  37.         {   
  38.             PropertyDescriptor desc   
  39.                 = TypeDescriptor.GetProperties(base.Component)["JQueryJs"];   
  40.             desc.SetValue(base.Component, value);   
  41.   
  42.         }   
  43.     }   
  44.     public bool JQueryUIJs {   
  45.         get  
  46.         {   
  47.             return JQueryManager.JQueryUIJs;   
  48.         }   
  49.         set  
  50.         {   
  51.             PropertyDescriptor desc    
  52.                 = TypeDescriptor.GetProperties(base.Component)["JQueryUIJs"];   
  53.             desc.SetValue(base.Component, value);   
  54.         }   
  55.     }   
  56.     public JQSkin Skins {   
  57.         get  
  58.         {   
  59.             return JQueryManager.Skins;   
  60.         }   
  61.         set  
  62.         {   
  63.             PropertyDescriptor desc    
  64.                 = TypeDescriptor.GetProperties(base.Component)["Skins"];   
  65.             desc.SetValue(base.Component, value);   
  66.         }   
  67.     }   
  68.   
  69.     public bool JQueryLngZh_CN {   
  70.         get  
  71.         {   
  72.             return JQueryManager.JQueryLngZh_CN;   
  73.         }   
  74.         set  
  75.         {   
  76.             PropertyDescriptor desc    
  77.                 = TypeDescriptor.GetProperties(base.Component)["JQueryLngZh_CN"];   
  78.             desc.SetValue(base.Component, value);   
  79.         }   
  80.     }   
  81.   
  82. }   

最后需要对JQuery Script Manager 类进行声明.

Code:
  1. [DesignerAttribute(typeof(JQeryManagerDesigner))]   
  2. public class JQueryManager:Control  

即可以实现!

待续....

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值