当前文件路径:AcomStore/Components/Jscript.cs 
1
using System;
2
using System.Data;
3
using System.Configuration;
4
using System.Collections;
5
using System.Web;
6
//该源码下载自www.51aspx.com(51aspx.com)
7
8
namespace AcomLb.Components
9
...{
10
/**//// <summary>
11
/// 一些常用的Js调用
12
/// <summary>
13
public class Jscript
14
...{
15
16
/**//// 弹出JavaScript小窗口
17
/// </summary>
18
/// <param name="js">窗口信息</param>
19
public static void Alert(string message)
20
...{
21
...#region
22
string js = @"<Script language='JavaScript'>
23
alert('" + message + "');</Script>";
24
HttpContext.Current.Response.Write(js);
25
26
#endregion
27
}
28
29
/**//// <summary>
30
/// 弹出JavaScript小窗口,并返回上一步
31
/// </summary>
32
/// <param name="message">窗口信息</param>
33
public static void AlertAndGoBack(string message)
34
...{
35
string js = @"<Script language='JavaScript'>
36
alert('" + message + "');history.go(-1);</Script>";
37
HttpContext.Current.Response.Write(js);
38
}
39
40
/**//// <summary>
41
/// 运行JS代码
42
/// </summary>
43
/// <param name="ScriptCode">脚本代码</param>
44
public static void RunJs(string ScriptCode)
45
...{
46
...#region
47
string js = @"<Script language='JavaScript'>
48
" + ScriptCode + ";</Script>";
49
HttpContext.Current.Response.Write(js);
50
#endregion
51
}
52
53
/**//// <summary>
54
/// 弹出消息框并且转向到新的URL
55
/// </summary>
56
/// <param name="message">消息内容</param>
57
/// <param name="toURL">连接地址</param>
58
public static void AlertAndRedirect(string message, string toURL)
59
...{
60
...#region
61
string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
62
HttpContext.Current.Response.Write(string.Format(js, message, toURL));
63
#endregion
64
}
65
66
public static void AlertForSave(string message)
67
...{
68
string RamCode = StrHelper.GetRamCode();
69
string Url = HttpContext.Current.Request.Url.ToString();
70
if (Url.IndexOf('?') > 0)
71
Url = string.Format("{0}&RamCode={1}", Url, RamCode);
72
else
73
Url = string.Format("{0}?RamCode={1}", Url, RamCode);
74
75
string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
76
HttpContext.Current.Response.Write(string.Format(js, message, Url));
77
}
78
79
/**//// <summary>
80
/// 回到历史页面
81
/// </summary>
82
/// <param name="value">-1/1</param>
83
public static void GoHistory(int value)
84
...{
85
...#region
86
string js = @"<Script language='JavaScript'>
87
history.go({0});
88
</Script>";
89
HttpContext.Current.Response.Write(string.Format(js, value));
90
#endregion
91
}
92
93
/**//// <summary>
94
/// 关闭当前窗口
95
/// </summary>
96
public static void CloseWindow()
97
...{
98
...#region
99
string js = @"<Script language='JavaScript'>
100
parent.opener=null;window.close();
101
</Script>";
102
HttpContext.Current.Response.Write(js);
103
HttpContext.Current.Response.End();
104
#endregion
105
}
106
107
/**//// <summary>
108
/// 刷新父窗口
109
/// </summary>
110
public static void RefreshParent(string url)
111
...{
112
...#region
113
string js = @"<Script language='JavaScript'>
114
window.opener.location.href='" + url + "';window.close();</Script>";
115
HttpContext.Current.Response.Write(js);
116
#endregion
117
}
118
119
120
/**//// <summary>
121
/// 刷新打开窗口
122
/// </summary>
123
public static void RefreshOpener()
124
...{
125
...#region
126
string js = @"<Script language='JavaScript'>
127
opener.location.reload();
128
</Script>";
129
HttpContext.Current.Response.Write(js);
130
#endregion
131
}
132
133
134
/**//// <summary>
135
/// 打开指定大小的新窗体
136
/// </summary>
137
/// <param name="url">地址</param>
138
/// <param name="width">宽</param>
139
/// <param name="heigth">高</param>
140
/// <param name="top">头位置</param>
141
/// <param name="left">左位置</param>
142
public static void OpenWebFormSize(string url, int width, int heigth, int top, int left)
143
...{
144
...#region
145
string js = @"<Script language='JavaScript'>window.open('" + url + @"','','height=" + heigth + ",width=" + width + ",top=" + top + ",left=" + left + ",location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=no,directories=no');</Script>";
146
147
HttpContext.Current.Response.Write(js);
148
#endregion
149
}
150
151
152
/**//// <summary>
153
/// 转向Url制定的页面
154
/// </summary>
155
/// <param name="url">连接地址</param>
156
public static void JavaScriptLocationHref(string url)
157
...{
158
...#region
159
string js = @"<Script language='JavaScript'>
160
window.location.replace('{0}');
161
</Script>";
162
js = string.Format(js, url);
163
HttpContext.Current.Response.Write(js);
164
#endregion
165
}
166
167
/**//// <summary>
168
/// 打开指定大小位置的模式对话框
169
/// </summary>
170
/// <param name="webFormUrl">连接地址</param>
171
/// <param name="width">宽</param>
172
/// <param name="height">高</param>
173
/// <param name="top">距离上位置</param>
174
/// <param name="left">距离左位置</param>
175
public static void ShowModalDialogWindow(string webFormUrl, int width, int height, int top, int left)
176
...{
177
...#region
178
string features = "dialogWidth:" + width.ToString() + "px"
179
+ ";dialogHeight:" + height.ToString() + "px"
180
+ ";dialogLeft:" + left.ToString() + "px"
181
+ ";dialogTop:" + top.ToString() + "px"
182
+ ";center:yes;help=no;resizable:no;status:no;scroll=yes";
183
ShowModalDialogWindow(webFormUrl, features);
184
#endregion
185
}
186
187
public static void ShowModalDialogWindow(string webFormUrl, string features)
188
...{
189
string js = ShowModalDialogJavascript(webFormUrl, features);
190
HttpContext.Current.Response.Write(js);
191
}
192
193
public static string ShowModalDialogJavascript(string webFormUrl, string features)
194
...{
195
...#region
196
string js = @"<script language=javascript>
197
showModalDialog('" + webFormUrl + "','','" + features + "');</script>";
198
return js;
199
#endregion
200
}
201
202
以下函数在页面上引用AJAX组件后,调用的启动脚本#region 以下函数在页面上引用AJAX组件后,调用的启动脚本
203
/**//// <summary>
204
/// Ajax启动脚本 For 引用AJAX组件的页
205
/// AjaxAlert:弹出对话框
206
/// </summary>
207
/// <param name="page">一般是this</param>
208
/// <param name="msg">对话框提示串</param>
209
public static void AjaxAlert(System.Web.UI.Page page, string msg)
210
...{
211
page.ClientScript.RegisterStartupScript(page.GetType(), "ajaxjs", string.Format("alert('{0}!')", msg), true);
212
}
213
214
/**//// <summary>
215
/// Ajax启动脚本 For 引用AJAX组件的页
216
/// 弹出对话框并跳转到URL页
217
/// </summary>
218
/// <param name="page">一般是this</param>
219
/// <param name="msg">对话框提示串</param>
220
/// <param name="url">跳往的地址</param>
221
public static void AjaxAlertAndLocationHref(System.Web.UI.Page page, string msg, string url)
222
...{
223
page.ClientScript.RegisterStartupScript(page.GetType(), "ajaxjs", string.Format("alert('{0}!');location.href='{1}';", msg, url), true);
224
225
}
226
/**//// <summary>
227
/// Ajax启动脚本 For 引用AJAX组件的页
228
/// JS语句
229
/// </summary>
230
/// <param name="page">一般是this</param>
231
/// <param name="js">如alert('test');</param>
232
public static void AjaxRunJs(System.Web.UI.Page page, string js)
233
...{
234
page.ClientScript.RegisterStartupScript(page.GetType(), "ajaxjs", string.Format("{0}", js), true);
235
}
236
237
/**//// <summary>
238
/// Ajax启动脚本 For 引用AJAX组件的页
239
/// JS语句
240
/// </summary>
241
/// <param name="page">一般是this</param>
242
/// <param name="js">如alert('test');</param>
243
public static void AjaxEndRunJs(System.Web.UI.Page page, string js)
244
...{
245
page.ClientScript.RegisterClientScriptBlock(page.GetType(), "ajaxjs", string.Format("{0}", js), true);
246
}
247
248
249
/**//// <summary>
250
/// Ajax启动脚本 For 引用AJAX组件的页
251
/// 转向到新的URL
252
/// </summary>