[控件学习-3]ComponentArt 的脚本注册机制学习
ComponentArt 的脚本注册判断还是很全面的,判断了各种情况,在控件开发学习中还是很值得借鉴的
一样画葫芦练手做了几个简单的控件:
All:SmartTip(改自ttyp的自动提示效果 ) ,自动提示
1.STextBox =>增加几个属性,只是为了拼Sql的时候字符转义方便些(TrimedText,SqlText,SqlTrimedText)
2.SButton = > 增加几个小属性,象confirm,waitmessage...
3.SImgButton = > 增加鼠标滑过,离开,按下的图片设置
4.SXpButton = > 按模板自动生成三组效果图片(鼠标滑过,离开,按下)
5.SGroupBox =>GroupBox 只有Caption属性,不过设计时写的不好(直接使用了系统的Designer).不直观,不过我自己够用了,改天有空再学习修改Designer
dll:/Files/walkingboy/LangZi.SmartSuite.Web.UI.WebControls.rar
注册代码源代码:
一样画葫芦练手做了几个简单的控件:
All:SmartTip(改自ttyp的自动提示效果 ) ,自动提示
1.STextBox =>增加几个属性,只是为了拼Sql的时候字符转义方便些(TrimedText,SqlText,SqlTrimedText)
2.SButton = > 增加几个小属性,象confirm,waitmessage...
3.SImgButton = > 增加鼠标滑过,离开,按下的图片设置
4.SXpButton = > 按模板自动生成三组效果图片(鼠标滑过,离开,按下)
5.SGroupBox =>GroupBox 只有Caption属性,不过设计时写的不好(直接使用了系统的Designer).不直观,不过我自己够用了,改天有空再学习修改Designer
dll:/Files/walkingboy/LangZi.SmartSuite.Web.UI.WebControls.rar
注册代码源代码:
1
2 /// <summary>
3 /// 绘制全局脚本
4 /// </summary>
5 /// <param name="output"></param>
6 /// <param name="sDefaultPath"></param>
7 /// <param name="sScriptFile"></param>
8 protected void WriteGlobalClientScript(HtmlTextWriter output, string sDefaultPath, string sScriptFile)
9 {
10 string sScript = GenerateClientScriptBlock(sDefaultPath, sScriptFile);
11 string sInstanceId = sScriptFile;
12
13 output.Write(sScript);
14 }
15
16
17
18
19 /// <summary>
20 /// 获取脚本块
21 /// </summary>
22 /// <param name="sDefaultPath"></param>
23 /// <param name="sScriptFile"></param>
24 /// <returns></returns>
25 private string GenerateClientScriptBlock(string sDefaultPath, string sScriptFile)
26 {
27 string sScript = string.Empty;
28 string sScriptLocation = string.Empty;
29 //相应版本 主版本+副版本+编译版本
30 string sVersionString =
31 Assembly.GetExecutingAssembly().GetName().Version.Major.ToString() + "_" +
32 Assembly.GetExecutingAssembly().GetName().Version.Minor.ToString() + "_" +
33 Assembly.GetExecutingAssembly().GetName().Version.Build.ToString();
34
35 if(this.ClientScriptLocation != string.Empty)//指定脚本位置
36 {
37 sScriptLocation = Path.Combine(Path.Combine(this.ClientScriptLocation, sVersionString), sScriptFile).Replace("\\", "/");
38 }
39 else
40 {
41 // First, try application config variable
42 //首先,先从程序配置文件读取web.config
43 string sLocation = ConfigurationSettings.AppSettings["ComponentArt.Web.UI.ClientScriptLocation"];
44 if(sLocation != null)
45 {
46 //脚本地址
47 sScriptLocation = Path.Combine(Path.Combine(sLocation, sVersionString), sScriptFile).Replace("\\", "/");
48 }
49
50 // Next, try server root
51 //IIS根目录
52 if(sScriptLocation == string.Empty)
53 {
54 try
55 {
56 string sStandardRootClientScriptPath = Path.Combine(Path.Combine("/componentart_webui_client", sVersionString), sScriptFile).Replace("\\", "/");
57
58 if(File.Exists(Context.Server.MapPath(sStandardRootClientScriptPath)))
59 {
60 sScriptLocation = sStandardRootClientScriptPath;
61 }
62 }
63 catch {}
64 }
65
66 // If failed, try application root
67 //程序根目录
68 if(sScriptLocation == string.Empty)
69 {
70 try
71 {
72 string sAppRootClientScriptPath = Path.Combine(Path.Combine(Path.Combine(Page.Request.ApplicationPath, "componentart_webui_client"), sVersionString), sScriptFile).Replace("\\", "/");
73
74 if(File.Exists(Context.Server.MapPath(sAppRootClientScriptPath)))
75 {
76 sScriptLocation = sAppRootClientScriptPath;
77 }
78 }
79 catch {}
80 }
81 }
82
83 if(sScriptLocation != string.Empty)
84 {
85 // Do we have a tilde?
86 if(sScriptLocation.StartsWith("~") && Context != null && Context.Request != null)
87 {
88 string sAppPath = Context.Request.ApplicationPath;
89 if(sAppPath.EndsWith("/"))
90 {
91 sAppPath = sAppPath.Substring(0, sAppPath.Length - 1);
92 }
93
94 sScriptLocation = sScriptLocation.Replace("~", sAppPath);
95 }
96
97 //连接外部JS文件
98 if(File.Exists(Context.Server.MapPath(sScriptLocation)))
99 {
100 sScript = "<script src=\"" + sScriptLocation + "\" type=\"text/javascript\"></script>";
101 }
102 else
103 {
104 throw new Exception(sScriptLocation + " not found");
105 }
106 }
107 else
108 {
109 // If everything failed, emit our internal script
110 //使用内嵌资源文件
111 sScript = Utils.DemarcateClientScript(GetResourceContent(sDefaultPath + "." + sScriptFile));
112 }
113
114 return sScript;
115 }
2 /// <summary>
3 /// 绘制全局脚本
4 /// </summary>
5 /// <param name="output"></param>
6 /// <param name="sDefaultPath"></param>
7 /// <param name="sScriptFile"></param>
8 protected void WriteGlobalClientScript(HtmlTextWriter output, string sDefaultPath, string sScriptFile)
9 {
10 string sScript = GenerateClientScriptBlock(sDefaultPath, sScriptFile);
11 string sInstanceId = sScriptFile;
12
13 output.Write(sScript);
14 }
15
16
17
18
19 /// <summary>
20 /// 获取脚本块
21 /// </summary>
22 /// <param name="sDefaultPath"></param>
23 /// <param name="sScriptFile"></param>
24 /// <returns></returns>
25 private string GenerateClientScriptBlock(string sDefaultPath, string sScriptFile)
26 {
27 string sScript = string.Empty;
28 string sScriptLocation = string.Empty;
29 //相应版本 主版本+副版本+编译版本
30 string sVersionString =
31 Assembly.GetExecutingAssembly().GetName().Version.Major.ToString() + "_" +
32 Assembly.GetExecutingAssembly().GetName().Version.Minor.ToString() + "_" +
33 Assembly.GetExecutingAssembly().GetName().Version.Build.ToString();
34
35 if(this.ClientScriptLocation != string.Empty)//指定脚本位置
36 {
37 sScriptLocation = Path.Combine(Path.Combine(this.ClientScriptLocation, sVersionString), sScriptFile).Replace("\\", "/");
38 }
39 else
40 {
41 // First, try application config variable
42 //首先,先从程序配置文件读取web.config
43 string sLocation = ConfigurationSettings.AppSettings["ComponentArt.Web.UI.ClientScriptLocation"];
44 if(sLocation != null)
45 {
46 //脚本地址
47 sScriptLocation = Path.Combine(Path.Combine(sLocation, sVersionString), sScriptFile).Replace("\\", "/");
48 }
49
50 // Next, try server root
51 //IIS根目录
52 if(sScriptLocation == string.Empty)
53 {
54 try
55 {
56 string sStandardRootClientScriptPath = Path.Combine(Path.Combine("/componentart_webui_client", sVersionString), sScriptFile).Replace("\\", "/");
57
58 if(File.Exists(Context.Server.MapPath(sStandardRootClientScriptPath)))
59 {
60 sScriptLocation = sStandardRootClientScriptPath;
61 }
62 }
63 catch {}
64 }
65
66 // If failed, try application root
67 //程序根目录
68 if(sScriptLocation == string.Empty)
69 {
70 try
71 {
72 string sAppRootClientScriptPath = Path.Combine(Path.Combine(Path.Combine(Page.Request.ApplicationPath, "componentart_webui_client"), sVersionString), sScriptFile).Replace("\\", "/");
73
74 if(File.Exists(Context.Server.MapPath(sAppRootClientScriptPath)))
75 {
76 sScriptLocation = sAppRootClientScriptPath;
77 }
78 }
79 catch {}
80 }
81 }
82
83 if(sScriptLocation != string.Empty)
84 {
85 // Do we have a tilde?
86 if(sScriptLocation.StartsWith("~") && Context != null && Context.Request != null)
87 {
88 string sAppPath = Context.Request.ApplicationPath;
89 if(sAppPath.EndsWith("/"))
90 {
91 sAppPath = sAppPath.Substring(0, sAppPath.Length - 1);
92 }
93
94 sScriptLocation = sScriptLocation.Replace("~", sAppPath);
95 }
96
97 //连接外部JS文件
98 if(File.Exists(Context.Server.MapPath(sScriptLocation)))
99 {
100 sScript = "<script src=\"" + sScriptLocation + "\" type=\"text/javascript\"></script>";
101 }
102 else
103 {
104 throw new Exception(sScriptLocation + " not found");
105 }
106 }
107 else
108 {
109 // If everything failed, emit our internal script
110 //使用内嵌资源文件
111 sScript = Utils.DemarcateClientScript(GetResourceContent(sDefaultPath + "." + sScriptFile));
112 }
113
114 return sScript;
115 }