componentart([控件学习-3]ComponentArt 的脚本注册机制学习[通俗易懂])

发布时间:2025-12-10 19:27:50 浏览次数:2

[控件学习-3]ComponentArt 的脚本注册机制学习[通俗易懂]-

[控件学习-3]ComponentArt 的脚本注册机制学习[通俗易懂]ComponentArt的脚本注册判断还是很全面的,判断了各种情况,在控件开发学习中还是很值得借鉴的一样画葫芦练手做了几个简单的控件:All:SmartTip(改自ttyp的自动提示效果),自动提示1.STextBox=>增加几个属性,只是为了拼Sql的时候字符转义方便些(TrimedText,SqlText,SqlTrimedTe…

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

注册代码源代码:

1



2


/**/
///

<summary>


3

///
绘制全局脚本

4

///

</summary>


5

///

<paramname=”output”></param>


6

///

<paramname=”sDefaultPath”></param>


7

///

<paramname=”sScriptFile”></param>



8

protected
voidWriteGlobalClientScript(HtmlTextWriteroutput,
stringsDefaultPath,
stringsScriptFile)


9


{


10

stringsScript=GenerateClientScriptBlock(sDefaultPath,sScriptFile);

11

stringsInstanceId=sScriptFile;

12


13
output.Write(sScript);

14
}


15



16



17



18



19


/**/
///

<summary>


20

///
获取脚本块

21

///

</summary>


22

///

<paramname=”sDefaultPath”></param>


23

///

<paramname=”sScriptFile”></param>


24

///

<returns></returns>



25

private
stringGenerateClientScriptBlock(
stringsDefaultPath,
stringsScriptFile)


26


{


27

stringsScript=
string.Empty;

28

stringsScriptLocation=
string.Empty;

29

//
相应版本主版本+副版本+编译版本


30

stringsVersionString=

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,tryapplicationconfigvariable

42

//
首先,先从程序配置文件读取web.config


43

stringsLocation=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,tryserverroot

51

//
IIS根目录


52

if(sScriptLocation==
string.Empty)

53


{


54

try

55


{


56

stringsStandardRootClientScriptPath=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

//
Iffailed,tryapplicationroot

67

//
程序根目录


68

if(sScriptLocation==
string.Empty)

69


{


70

try

71


{


72

stringsAppRootClientScriptPath=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

//
Dowehaveatilde?


86

if(sScriptLocation.StartsWith(“~”)&&Context!=
null&&Context.Request!=
null)

87


{


88

stringsAppPath=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=“<scriptsrc=\””+sScriptLocation+“\”type=\”text/javascript\”></script>”;

101
}

102

else

103


{


104

throw
newException(sScriptLocation+”notfound”);

105
}

106
}

107

else

108


{


109

//
Ifeverythingfailed,emitourinternalscript

110

//
使用内嵌资源文件


111
sScript=Utils.DemarcateClientScript(GetResourceContent(sDefaultPath+“.”+sScriptFile));

112
}

113


114

returnsScript;

115
}

分类:
软件发布区
本文转自浪子博客园博客,原文链接:http://www.cnblogs.com/walkingboy/archive/2005/11/25/284506.html,如需转载请自行联系原作者

需要做网站?需要网络推广?欢迎咨询客户经理 13272073477