分享
 
 
 

让ASP.NET简便使用SCRIPT

王朝asp·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

在开发ASP.NET应用程序过程中编写Script是件很烦人的事情,其实我们可以把常用的Script装成相应的.NET组件在服务端调用,这样可以大大简化Script的编写还提高的Script的重用。

以下是常用的打开模式窗体并获取返回值的类调用,实际上可以给设置多个参数传入和不同控件获取不同返回值的结果.

定义打开窗体并设置返回值脚本类:

HFSoft.Web.Scripts.ShowModalDialog dialog=new HFSoft.Web.Scripts.ShowModalDialog(

XXX.Units.Config.WebBoot+"Appunit/WindowOpenDialog.aspx",

FrmFailureLogSearch.PageURI());

dialog.Height=400;

dialog.Width=600;

dialog.ReturnElements.Add(new HFSoft.Web.Scripts.ReturnElement(this.txtReturn.ClientID,"ReturnString"));

HFSoft.Web.Scripts.RegisterScript.RegiOnClick(cmdSearch,dialog);

打开窗体设置返回值的代码:

HFSoft.Web.Scripts.ReturnValues returnValue=new HFSoft.Web.Scripts.ReturnValues();

returnValue.Add("ReturnString",filter);

HFSoft.Web.Scripts.RegisterScript.RegiPageClient(this,"return",returnValue);

打开窗体类的代码(其实很多Script都可以通过这样的方式来封装).

00006 namespace HFSoft . Web . Scripts

00007 {

00008 /// <summary>

00009 /// 创建打开窗体脚本类

00010 /// 注意:返回值参数据接收的数据格式必须

00011 /// key=value|key1=value1|.....

00012 /// </summary>

00013 public class ShowModalDialog : IExecuteScript

00014 {

00015 private const string _Dialog ="window.showModalDialog({0},' ',' dialogHeight : { 1 } px ;

dialogWidth : { 2 } px ; edge : Raised ; center : Yes ; help : No ; resizable : No ; status : No ; scroll :

Yes ;');" ;

00016 #region IExecuteScript 成员

00017 private bool mParent = false ;

00018 /// <summary>

00019 /// 是否需要加载父指向

00020 /// </summary>

00021 public bool Parent

00022 {

00023 get

00024 {

00025 // TODO: 添加 SetElementsValue.Parent getter 实现

00026 return mParent ;

00027 }

00028 set

00029 {

00030 // TODO: 添加 SetElementsValue.Parent setter 实现

00031 mParent = value ;

00032 }

00033 }

00034 private string GetParent ()

00035 {

00036 if ( Parent )

00037 return "parent." ;

00038 return "" ;

00039 }

00040 /// <summary>

00041 /// 构造对象

00042 /// </summary>

00043 /// <param name="pageContainer">容器页</param>

00044 /// <param name="openPage">具本打开的页面</param>

00045 public ShowModalDialog ( string pageContainer , string openPage )

00046 {

00047 PageContainer = pageContainer ;

00048 OpenPage = openPage ;

00049 }

00050 public const string PageUrlTag ="pageurl" ;

00051 /// <summary>

00052 /// 生成脚本

00053 /// </summary>

00054 /// <returns>string</returns>

00055 public string Execute ()

00056 {

00057 // TODO: 添加 ShowModalDialog.Execute 实现

00058 string url ="' " + PageContainer +" ? pageurl ='+" + GetPage ();

00059 url = string . Format ( _Dialog , url , Height , Width );

00060 url = GetParent () + url ;

00061 if ( ReturnElements . Count >0)

00062 {

00063 url = "var getvalue=" + url +";if(getvalue != null){" ;

00064 foreach ( ReturnElement item in ReturnElements )

00065 {

00066 url += item . GetScript ( GetParent ());

----------------------------------------------------

00067 }

00068 url +="}" ;

00069 return url +";" ;

00070 }

00071 return url +";" ;

00072 }

00073

00074 #endregion

00075 private string mPageContainer ;

00076 /// <summary>

00077 /// 获取或设置容器页(包含路径)

00078 /// </summary>

00079 public string PageContainer

00080 {

00081 get

00082 {

00083 return mPageContainer ;

00084 }

00085 set

00086 {

00087 mPageContainer = value ;

00088 }

00089 }

00090 private string mOpenPage ;

00091 /// <summary>

00092 /// 打开的页(包含路径)

00093 /// </summary>

00094 public string OpenPage

00095 {

00096 get

00097 {

00098 return mOpenPage ;

00099 }

00100 set

00101 {

00102 mOpenPage = value ;

00103 }

00104 }

00105 private int mHeight =400;

00106 /// <summary>

00107 /// 获取或设置打开窗体的高度

00108 /// </summary>

00109 public int Height

00110 {

00111 get

00112 {

00113 return mHeight ;

00114 }

00115 set

00116 {

00117 mHeight = value ;

00118 }

00119 }

00120 private int mWidth =400;

00121 /// <summary>

00122 /// 获取或设置打开窗体的宽度

00123 /// </summary>

00124 public int Width

00125 {

00126 get

00127 {

00128 return mWidth ;

00129 }

00130 set

00131 {

---------------------------------------

00132 mWidth = value ;

00133 }

00134 }

00135 private ReturnElementCollections mReturnElements = new ReturnElementCollections ();

00136 /// <summary>

00137 /// 获取返回值元素集

00138 /// </summary>

00139 public ReturnElementCollections ReturnElements

00140 {

00141 get

00142 {

00143 return mReturnElements ;

00144 }

00145 }

00146 private ParameterCollection mParameters = new ParameterCollection ();

00147 /// <summary>

00148 /// 获取打开页面的参数集

00149 /// </summary>

00150 public ParameterCollection Parameters

00151 {

00152 get

00153 {

00154 return mParameters ;

00155 }

00156 }

00157 private string GetPage ()

00158 {

00159 if ( Parameters . Count ==0)

00160 return "' "+OpenPage+" '" ;

00161 System . Text . StringBuilder sb = new System . Text . StringBuilder ();

00162 sb . Append ("' "+OpenPage+" '" );

00163 string param ="" ;

00164 string parent = GetParent ();

00165 for ( int i =0; i < Parameters . Count ; i ++)

00166 {

00167 if ( Parameters [ i ]. Element == ElementType . Element )

00168 {

00169 param ="' " + Parameters[i].Name +" =' + " + parent +"document.all('

"+Parameters[i].Value + " ').value" ;

00170 }

00171 else if ( Parameters [ i ]. Element == ElementType . Select )

00172 {

00173 param ="' " + Parameters[i].Name +" =' + " + parent +"__getSeletedButton(" + parent +

"document.all(' "+Parameters[i].Value + " '))" ;

00174 }

00175 if ( i ==0)

00176 {

00177 sb . Append ("+' "+System.Web.HttpUtility.UrlEncode(" ?") +" '+" + param );

00178 }

00179 else

00180 {

00181 sb . Append ("+' "+System.Web.HttpUtility.UrlEncode(" &") +" '+" + param );

00182 }

00183 }

00184 return sb . ToString ();

00185 }

00186

00187

00188

00189 }

00190 #region subClass

00191 public enum ElementType

00192 {

00193 None ,

00194 Element ,

00195 Select

--------------------------------------------------

00196 }

00197 /// <summary>

00198 /// 参数描述类

00199 /// </summary>

00200 public class Parameter

00201 {

00202 /// <summary>

00203 /// 构造参数对象

00204 /// </summary>

00205 public Parameter ()

00206 {

00207 }

00208 /// <summary>

00209 /// 构造指定名称和值的参数对象

00210 /// </summary>

00211 /// <param name="name">参数名称</param>

00212 /// <param name="value">参数值</param>

00213 public Parameter ( string name , string value )

00214 {

00215 Name = name ;

00216 Value = value ;

00217 }

00218 /// <summary>

00219 /// 构造指定名称和值的参数对象

00220 /// </summary>

00221 /// <param name="name">参数名称</param>

00222 /// <param name="value">参数值</param>

00223 /// <param name="iselement">值是否元素名称</param>

00224 public Parameter ( string name , string value , ElementType element )

00225 {

00226 Name = name ;

00227 Value = value ;

00228 Element = element ;

00229 }

00230

00231 private string mName ;

00232 /// <summary>

00233 /// 获取或设置参数名称

00234 /// </summary>

00235 public string Name

00236 {

00237 get

00238 {

00239 return mName ;

00240 }

00241 set

00242 {

00243 mName = value ;

00244 }

00245 }

00246 private string mValue ;

00247 /// <summary>

00248 /// 获取或设置参数值

00249 /// </summary>

00250 public string Value

00251 {

00252 get

00253 {

00254 return mValue

[1] [2] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有