Developer Express,熟悉Dephi的人对这个大名不会陌生。Developer Express的VCL控件可是Dephi里经典的第三方控件,获得很多奖项,给Dephi程序员提供了不少方便。我们今天提到的是他为Asp.net写的一套控件,虽说达不到VCL那套控件的辉煌,但其强大的功能也不容小视。
我在实际工作中曾用到这套控件。当时我们开发组的成员每个人负责各自的模块,而在各自模块中都获多或少的用到了这套控件。在使用这套控件中,它引用的js脚本文件路径和资源路径缺省的情况下会指向dxWebControls虚拟目录下Scripts与Images目录中。恰恰我们的客户的服务器上不允许新建dxWebControls这样的虚拟目录,所以造成引用的文件无法找到。为此,我通过修改该套控件的源码来实现在部署的时候设置脚本和资源路径。修改细节如下:
1、在脚本目录中新建一个文件ASPxClientConfig_2_0_1.js添加代码:
var sASPxClientRootPath = " /dxWebControls/ " ;2、替换ASPxGridCore_2_0_1.js、ASPxGridRender_2_0_1.js、ASPxGridRenderCore_2_0_1.js、ASPxListEditors_2_0_1.js中 "/dxWebControls/ 为 sASPxClientRootPath+"
3、修改ClientScriptsResistrator.cs 文件在ScriptsRegistrator类中添加如下代码:
protected static readonly string ASPxClientConfigScriptKey = " ASPxClientConfig " ; protected static void RegisterClientConfig(Page page, string path) { string scriptblock = " <script language="JavaScript1.2" > " + " var sASPxClientRootPath = " " + Utils.DefaultClientFilesRootPath + " " " + " </script> " ; page.RegisterClientScriptBlock(ASPxClientConfigScriptKey,scriptblock ); // RegisterScriptFile(page, ASPxClientConfigScriptKey, path); }
4、修改ASPxGrid.cs文件 在ASPxGridScriptsRegistrator类中的RegisterASPxGridScripts方法里添加如下代码:
RegisterClientConfig(page, path);
5、修改ASPxListEditors.cs文件 在ListEditScriptsRegistrator类的RegisterListEditorsClientScript方法里添加如下代码:
RegisterClientConfig(page, path);
6、修改Utils.cs 修改类Utils 写入下代码:
public const string InnerDefaultImageFilesPath = " /dxWebControls/Images/ " ; public const string InnerDefaultScriptFilesPath = " /dxWebControls/Scripts/ " ; public static string DefaultImageFilesPath { get { IDictionary pathconfig = (IDictionary) System.Configuration.ConfigurationSettings.GetConfig( " ASPxClientRootPath " ); if (pathconfig != null ) { string strRoot = ( string )pathconfig[ " value " ]; strRoot = strRoot.Replace( " / " , " / " ); if (strRoot.EndsWith( " / " )) return strRoot + " Images/ " ; else return strRoot + " /Images/ " ; } else { return " /dxWebControls/Images/ " ; } } } public static string DefaultScriptFilesPath { get { IDictionary pathconfig = (IDictionary) System.Configuration.ConfigurationSettings.GetConfig( " ASPxClientRootPath " ); if (pathconfig != null ) { string strRoot = ( string )pathconfig[ " value " ]; strRoot = strRoot.Replace( " / " , " / " ); if (strRoot.EndsWith( " / " )) return strRoot + " Scripts/ " ; else return strRoot + " /Scripts/ " ; } else { return " /dxWebControls/Scripts/ " ; } } } public static string DefaultClientFilesRootPath { get { IDictionary pathconfig = (IDictionary) System.Configuration.ConfigurationSettings.GetConfig( " ASPxClientRootPath " ); if (pathconfig != null ) { string strRoot = ( string )pathconfig[ " value " ]; strRoot = strRoot.Replace( " / " , " / " ); if ( ! strRoot.EndsWith( " / " )) strRoot += " / " ; return strRoot; } else { return " /dxWebControls/ " ; } } }
7、修改LookAndFeelController.cs 修改ASPxLookAndFeelController类的ImageFilesPath和ScriptFilesPath两个属性如下:
[Description( " Gets or sets the root path of all images used by the DeveloperExpress Web Controls. " ), NotifyParentProperty( true ), DefaultValue(Utils.InnerDefaultImageFilesPath)] public string ImageFilesPath { get { // return GetStringProperty("ImageFilesPath", Utils.DefaultImageFilesPath); string path = GetStringProperty( " ImageFilesPath " , Utils.DefaultImageFilesPath); if (path.StartsWith( " [ " ) && path.EndsWith( " ] " )) { path = path.Substring( 1 ,path.Length - 2 ); return Utils.DefaultImageFilesPath + path + " / " ; } else return path; } set { SetStringProperty( " ImageFilesPath " , Utils.DefaultImageFilesPath, value); OnPathChange(); } } [Description( " Gets or sets the virtual path of all service Java script files used by DeveloperExpress Web Controls. " ), NotifyParentProperty( true ), DefaultValue(Utils.InnerDefaultScriptFilesPath)] public string ScriptFilesPath { get { // return GetStringProperty("ScriptFilesPath", Utils.DefaultScriptFilesPath); string path = GetStringProperty( " ScriptFilesPath " , Utils.DefaultScriptFilesPath); if (path.StartsWith( " [ " ) && path.EndsWith( " ] " )) { path = path.Substring( 1 ,path.Length - 2 ); return Utils.DefaultScriptFilesPath + path + " / " ; } else return path; } set { SetStringProperty( " ScriptFilesPath " , Utils.DefaultScriptFilesPath, value); OnPathChange(); } }
8、修改 /DevExpress.Web.ASPxDataControls/Themes/Suede Flat/ASPxLookAndFeelController.xml /DevExpress.Web.ASPxDataControls/Themes/Suede UltraFlat/ASPxLookAndFeelController.xml /DevExpress.Web.ASPxDataControls/Themes/Vagabond Flat/ASPxLookAndFeelController.xml /DevExpress.Web.ASPxDataControls/Themes/Vagabond UltraFlat/ASPxLookAndFeelController.xml 文件
将 ImageFilesPath="/dxWebControls/Images/Suede/" 改为 ImageFilesPath="[Suede]" 将 ImageFilesPath="/dxWebControls/Images/Suede/" 改为 ImageFilesPath="[Suede]" 将 ImageFilesPath="/dxWebControls/Images/Vagabond Flat/" 改为 ImageFilesPath="[Vagabond Flat]" 将 ImageFilesPath="/dxWebControls/Images/Vagabond/" 改为 ImageFilesPath="[Vagabond]"
经过以上修改后,将重新编译后的dll和脚本文件覆盖工程中的相应文件。然后在Web.config文件里的<configuration>节点下添加:
< configSections > < section name ="ASPxClientRootPath" type ="System.Configuration.SingleTagSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> </ configSections > < ASPxClientRootPath value ="/DevWebControls/" />其中ASPxClientRootPath设置项节点的value值就是表示控件引用的脚本和资源路径的跟目录。这样当给客户部署产品的时候,只需修改这个值就能满足要求了。
