前面基本实现了ASP.NET MVC的 JQueryUI控件,现在准备写一套ASP.NET的JQueryUI控件开发,
今天先写一个JQueryScriptManager的实现.(基于ASP.NET MVC的基础上进行的开发,最终写成的控件即可以应用于ASP.NET也可以应用于ASP.NET MVC).
先上图:
三个引入使用的是Bool类型属性,
皮肤使用枚举类型,此类型在前面已定义:
- public enum JQSkin
- {
- blitzer,
- humanity,
- redmond,
- smoothness,
- sunny,
- ui_darkness,
- ui_lightness,
- start,
- overcast,
- le_frog,
- flick,
- pepper_grinder
- }
一、实现 控件设计时显示JQuery Script Manager -htt://www.hahaman.cn效果
- public class JQueryManager:Control
- protected override void Render(HtmlTextWriter writer)
- {
- base.Render(writer);
- if (base.DesignMode)
- {
- 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>");
- }
- }
即可实现,
二、设置功能实现:
首先需要实现JQuery Script Manager 类中的属性
- //属性定义
- public bool JQueryJs { get; set; }
- public bool JQueryUIJs { get; set; }
- public JQSkin Skins { get; set; }
- public bool JQueryLngZh_CN { get; set; }
- //初始化
- public JQueryManager()
- {
- this.JQueryJs = true;
- this.JQueryUIJs = true;
- this.JQueryLngZh_CN = true;
- this.Skins = JQSkin.smoothness;
- }
- //加载处理
- protected override void OnLoad(EventArgs e)
- {
- if (JQueryJs)
- this.Page.ClientScript.RegisterClientScriptInclude("jquery", Page.ClientScript.GetWebResourceUrl(typeof(JQueryUIExt), "Hahaman.Mvc.UI.jquery-1.4.2.min.js"));
- if (JQueryUIJs)
- {
- this.Page.ClientScript.RegisterClientScriptInclude("jqueryui", Page.ClientScript.GetWebResourceUrl(typeof(JQueryUIExt), "Hahaman.Mvc.UI.jquery-ui-1.8.2.custom.min.js"));
- string skin = Skins.ToString();
- Literal lit = new Literal();
- 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/" />";
- this.Page.Header.Controls.Add(lit);
- }
- if (JQueryLngZh_CN)
- this.Page.ClientScript.RegisterClientScriptInclude("jquerylng", Page.ClientScript.GetWebResourceUrl(typeof(JQueryUIExt), "Hahaman.Mvc.UI.jquery.ui.datepicker-zh-CN.js"));
- }
实现设计类:JQeryManagerDesigner
- public class JQeryManagerDesigner : ControlDesigner,IComponent
- {
- public JQeryManagerDesigner()
- : base()
- {
- }
- public override DesignerActionListCollection ActionLists
- {
- get
- {
- DesignerActionListCollection actionList
- = new DesignerActionListCollection();
- actionList.Add(new JQueryManagerActionList(base.Component));
- return actionList;
- }
- }
- #region IComponent 成员
- public event EventHandler Disposed;
- public ISite Site
- {
- get
- {
- throw new NotImplementedException();
- }
- set
- {
- throw new NotImplementedException();
- }
- }
- #endregion
- }
ActionList类:JQueryManagerActionList
- public class JQueryManagerActionList : DesignerActionList
- {
- IComponent _parent;
- public JQueryManagerActionList(IComponent c)
- : base(c)
- {
- _parent = c;
- }
- private DesignerActionItemCollection items;
- public override DesignerActionItemCollection GetSortedActionItems()
- {
- if (items == null)
- {
- items = new DesignerActionItemCollection();
- items.Add(new DesignerActionHeaderItem("JQuery Script设置"));
- items.Add(new DesignerActionPropertyItem("JQueryJs", "引入JQuery.js"));
- items.Add(new DesignerActionPropertyItem("JQueryUIJs", "引入JQuery.UI.js"));
- items.Add(new DesignerActionPropertyItem("JQueryLngZh_CN","引入JQuery中文语言包"));
- items.Add(new DesignerActionPropertyItem("Skins", "皮肤"));
- }
- return items;
- }
- private JQueryManager JQueryManager
- {
- get
- {
- return (JQueryManager)_parent;
- }
- }
- public bool JQueryJs {
- get
- {
- return JQueryManager.JQueryJs;
- }
- set
- {
- PropertyDescriptor desc
- = TypeDescriptor.GetProperties(base.Component)["JQueryJs"];
- desc.SetValue(base.Component, value);
- }
- }
- public bool JQueryUIJs {
- get
- {
- return JQueryManager.JQueryUIJs;
- }
- set
- {
- PropertyDescriptor desc
- = TypeDescriptor.GetProperties(base.Component)["JQueryUIJs"];
- desc.SetValue(base.Component, value);
- }
- }
- public JQSkin Skins {
- get
- {
- return JQueryManager.Skins;
- }
- set
- {
- PropertyDescriptor desc
- = TypeDescriptor.GetProperties(base.Component)["Skins"];
- desc.SetValue(base.Component, value);
- }
- }
- public bool JQueryLngZh_CN {
- get
- {
- return JQueryManager.JQueryLngZh_CN;
- }
- set
- {
- PropertyDescriptor desc
- = TypeDescriptor.GetProperties(base.Component)["JQueryLngZh_CN"];
- desc.SetValue(base.Component, value);
- }
- }
- }
最后需要对JQuery Script Manager 类进行声明.
- [DesignerAttribute(typeof(JQeryManagerDesigner))]
- public class JQueryManager:Control
即可以实现!
待续....