.CS中的JavaScript
来源:互联网 发布:武汉黑马程序员 编辑:程序博客网 时间:2024/05/19 19:30
using System;
using System.Web;
using System.Web.UI;
using System.Text;
using System.IO;
using System.Net;
using System.Collections.Generic;
using System.Configuration;
using System.Xml;
/**//// <summary>
/// Cs里JAVASCRIPT控制
/// </summary>
/// Author: 姜辉
/// History:
/// 2007-02-08 姜辉 [创建]
namespace UpFile
...{
public class Utility : Page
...{
/**//// <summary>
/// 弹出提示
/// </summary>
/// <param name="message"></param>
protected void MsgBox(string message)
...{
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = this.Page.ClientScript;
// Define the name and type of the client scripts on the page.
String csname = "PopupScript";
Type cstype = this.GetType();
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname))
...{
String cstext = "alert('" + Server.HtmlEncode(message) + "');";
cs.RegisterStartupScript(cstype, csname, cstext, true);
}
}
/**//// <summary>
/// 弹出提示并转向url
/// </summary>
/// <param name="message"></param>
/// <param name="url"></param>
protected void MsgBox(string message, string url)
...{
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = this.Page.ClientScript;
// Define the name and type of the client scripts on the page.
String csname = "PopupScript";
Type cstype = this.GetType();
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
...{
String cstext = "alert('" + Server.HtmlEncode(message) + "');window.location='" + url + "';";
cs.RegisterStartupScript(cstype, csname, cstext, true);
}
}
/**//// <summary>
/// 最大化打开窗口
/// </summary>
/// <param name="pageName"></param>
public static void COpenMax(string pageName)
...{
//Get a ClientScriptManager reference from the Page class
ClientScriptManager cs = this.Page.ClientScript;
//Define the name and type of the client scripts on the page
String csname = "open";
Type cstype = this.GetType();
//builder the script text
StringBuilder cstext = new StringBuilder();
cstext.Append("<script language='javascript'>");
cstext.Append("{window.open('" + pageName + "','aa','width='+screen.width+' height='+screen.height+' top=0 left=0 toolbar=no menubar=no resizable=yes status=yes');}");
cstext.Append("</script>");
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname))
...{
cs.RegisterStartupScript(cstype, csname, cstext.ToString(), true);
}
}
/**//// <summary>
/// 全屏窗口
/// </summary>
/// <param name="pageName"></param>
public static void COpenFullScreen(string pageName)
...{
//Get a ClientScriptManager reference from the Page class
ClientScriptManager cs = this.Page.ClientScript;
//Define the name and Type of the client scripts on the page
String csname = "open";
Type cstype = this.GetType();
//builder the script text
StringBuilder cstext = new StringBuilder();
cstext.Append("<script language='javascript'>");
cstext.Append("{window.open('" + pageName + "','aa','fullscreen');}");
cstext.Append("</script>");
// Check to see if the startup script is already registered
if (!cs.IsClientScriptBlockRegistered(cstype, csname))
...{
cs.RegisterStartupScript(cstype, csname, cstext.ToString(), true);
}
}
/**//// <summary>
/// 打开最大化模式窗口
/// </summary>
/// <param name="pageName"></param>
public static void COpenModalDialog(string pageName)
...{
//Get a ClientScriptManager reference from the Page class
ClientScriptManager cs = this.Page.ClientScript;
//Define the name and Type of the client script on the page
String csname = "showModalDialog";
Type cstype = this.GetType();
//builder the script text
StringBuilder cstext = new StringBuilder();
cstext.Append("<script language='javascript'>");
cstext.Append("{showModalDialog('" + pageName + "','aa','dialogWidth:'+screen.width+'; dialogHeight:'+screen.height+'; dialogTop:0; dialogLeft:0; center:yes; help:no; resizable:yes; status=yes');}");
cstext.Append("</script>");
//Check to see if the startup script is already registered
if (!cs.IsClientScriptBlockRegistered(cstype, csname))
...{
cs.RegisterStartupScript(cstype, csname, cstext.ToString(), true);
}
}
/**//// <summary>
/// 打开规定大小的模式窗口
/// </summary>
/// <param name="MyPage"></param>
/// <param name="pageName"></param>
/// <param name="width"></param>
/// <param name="height"></param>
public static void COpenModalDialogSelf(string pageName, int width, int height)
...{
//Get a ClientScriptManager reference from the Page class
ClientScriptManager cs = this.Page.ClientScript;
//Define the name and Type of the client script on the page
String csname = "showModalDialog";
Type cstype = this.GetType();
//builder the script
StringBuilder cstext = new StringBuilder();
cstext.Append("<script language='javascript'>");
cstext.Append("{showModalDialog('" + pageName + "','aa','dialogWidth:'" + width.ToString() + "'; dialogHeight:'" + height.ToString() + "'; dialogTop:0; dialogLeft:0; center:yes; help:no; resizable:yes; status=yes');}");
cstext.Append("</script>");
//Check to see if the startup script is already registered
if (!cs.IsClientScriptBlockRegistered(cstype, csname))
...{
cs.RegisterStartupScript(cstype, csname, cstext.ToString(), true);
}
}
/**//// <summary>
/// 关闭窗口
/// </summary>
public static void CClose()
...{
//Get a ClientScriptManager reference from the Page class
ClientScriptManager cs = this.Page.ClientScript;
//Define the name and Type of the client script on the page
String csname = "close";
Type cstype = this.GetType();
// builder the script text
StringBuilder cstext = new StringBuilder();
cstext.Append("<script language='javascript'>");
cstext.Append("{window.opener='anyone';window.close();}");
cstext.Append("</script>");
//Check to see if the startup script is already registered
if (!cs.IsClientScriptBlockRegistered(cstype, csname))
...{
cs.RegisterStartupScript(cstype, csname, cstext.ToString(), true);
}
}
/**//// <summary>
/// 下载文件
/// </summary>
/// <param name="DstrFileName"></param>
/// <param name="YstrUrl"></param>
/// <returns></returns>
public static bool DownLoadFile(string DstrFileName, string YstrUrl)
...{
//打开上次下载的文件或新建文件
long lStartPos = 0;
System.IO.FileStream fs;
if (System.IO.File.Exists(DstrFileName))
...{
fs = System.IO.File.OpenWrite(DstrFileName);
lStartPos = fs.Length;
fs.Seek(lStartPos, System.IO.SeekOrigin.Current); //移动文件流中的当前指针
}
else
...{
fs = new System.IO.FileStream(DstrFileName, System.IO.FileMode.Create);
lStartPos = 0;
}
//打开网络连接
try
...{
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(YstrUrl);
if (lStartPos > 0)
request.AddRange((int)lStartPos); //设置Range值
//向服务器请求,获得服务器回应数据流
System.IO.Stream ns = request.GetResponse().GetResponseStream();
byte[] nbytes = new byte[512];
int nReadSize = 0;
nReadSize = ns.Read(nbytes, 0, 512);
while (nReadSize > 0)
...{
fs.Write(nbytes, 0, nReadSize);
nReadSize = ns.Read(nbytes, 0, 512);
}
fs.Close();
ns.Close();
//("下载完成");
return true;
}
catch
...{
fs.Close();
return false;
}
}
}
}
using System.Web;
using System.Web.UI;
using System.Text;
using System.IO;
using System.Net;
using System.Collections.Generic;
using System.Configuration;
using System.Xml;
/**//// <summary>
/// Cs里JAVASCRIPT控制
/// </summary>
/// Author: 姜辉
/// History:
/// 2007-02-08 姜辉 [创建]
namespace UpFile
...{
public class Utility : Page
...{
/**//// <summary>
/// 弹出提示
/// </summary>
/// <param name="message"></param>
protected void MsgBox(string message)
...{
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = this.Page.ClientScript;
// Define the name and type of the client scripts on the page.
String csname = "PopupScript";
Type cstype = this.GetType();
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname))
...{
String cstext = "alert('" + Server.HtmlEncode(message) + "');";
cs.RegisterStartupScript(cstype, csname, cstext, true);
}
}
/**//// <summary>
/// 弹出提示并转向url
/// </summary>
/// <param name="message"></param>
/// <param name="url"></param>
protected void MsgBox(string message, string url)
...{
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = this.Page.ClientScript;
// Define the name and type of the client scripts on the page.
String csname = "PopupScript";
Type cstype = this.GetType();
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
...{
String cstext = "alert('" + Server.HtmlEncode(message) + "');window.location='" + url + "';";
cs.RegisterStartupScript(cstype, csname, cstext, true);
}
}
/**//// <summary>
/// 最大化打开窗口
/// </summary>
/// <param name="pageName"></param>
public static void COpenMax(string pageName)
...{
//Get a ClientScriptManager reference from the Page class
ClientScriptManager cs = this.Page.ClientScript;
//Define the name and type of the client scripts on the page
String csname = "open";
Type cstype = this.GetType();
//builder the script text
StringBuilder cstext = new StringBuilder();
cstext.Append("<script language='javascript'>");
cstext.Append("{window.open('" + pageName + "','aa','width='+screen.width+' height='+screen.height+' top=0 left=0 toolbar=no menubar=no resizable=yes status=yes');}");
cstext.Append("</script>");
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname))
...{
cs.RegisterStartupScript(cstype, csname, cstext.ToString(), true);
}
}
/**//// <summary>
/// 全屏窗口
/// </summary>
/// <param name="pageName"></param>
public static void COpenFullScreen(string pageName)
...{
//Get a ClientScriptManager reference from the Page class
ClientScriptManager cs = this.Page.ClientScript;
//Define the name and Type of the client scripts on the page
String csname = "open";
Type cstype = this.GetType();
//builder the script text
StringBuilder cstext = new StringBuilder();
cstext.Append("<script language='javascript'>");
cstext.Append("{window.open('" + pageName + "','aa','fullscreen');}");
cstext.Append("</script>");
// Check to see if the startup script is already registered
if (!cs.IsClientScriptBlockRegistered(cstype, csname))
...{
cs.RegisterStartupScript(cstype, csname, cstext.ToString(), true);
}
}
/**//// <summary>
/// 打开最大化模式窗口
/// </summary>
/// <param name="pageName"></param>
public static void COpenModalDialog(string pageName)
...{
//Get a ClientScriptManager reference from the Page class
ClientScriptManager cs = this.Page.ClientScript;
//Define the name and Type of the client script on the page
String csname = "showModalDialog";
Type cstype = this.GetType();
//builder the script text
StringBuilder cstext = new StringBuilder();
cstext.Append("<script language='javascript'>");
cstext.Append("{showModalDialog('" + pageName + "','aa','dialogWidth:'+screen.width+'; dialogHeight:'+screen.height+'; dialogTop:0; dialogLeft:0; center:yes; help:no; resizable:yes; status=yes');}");
cstext.Append("</script>");
//Check to see if the startup script is already registered
if (!cs.IsClientScriptBlockRegistered(cstype, csname))
...{
cs.RegisterStartupScript(cstype, csname, cstext.ToString(), true);
}
}
/**//// <summary>
/// 打开规定大小的模式窗口
/// </summary>
/// <param name="MyPage"></param>
/// <param name="pageName"></param>
/// <param name="width"></param>
/// <param name="height"></param>
public static void COpenModalDialogSelf(string pageName, int width, int height)
...{
//Get a ClientScriptManager reference from the Page class
ClientScriptManager cs = this.Page.ClientScript;
//Define the name and Type of the client script on the page
String csname = "showModalDialog";
Type cstype = this.GetType();
//builder the script
StringBuilder cstext = new StringBuilder();
cstext.Append("<script language='javascript'>");
cstext.Append("{showModalDialog('" + pageName + "','aa','dialogWidth:'" + width.ToString() + "'; dialogHeight:'" + height.ToString() + "'; dialogTop:0; dialogLeft:0; center:yes; help:no; resizable:yes; status=yes');}");
cstext.Append("</script>");
//Check to see if the startup script is already registered
if (!cs.IsClientScriptBlockRegistered(cstype, csname))
...{
cs.RegisterStartupScript(cstype, csname, cstext.ToString(), true);
}
}
/**//// <summary>
/// 关闭窗口
/// </summary>
public static void CClose()
...{
//Get a ClientScriptManager reference from the Page class
ClientScriptManager cs = this.Page.ClientScript;
//Define the name and Type of the client script on the page
String csname = "close";
Type cstype = this.GetType();
// builder the script text
StringBuilder cstext = new StringBuilder();
cstext.Append("<script language='javascript'>");
cstext.Append("{window.opener='anyone';window.close();}");
cstext.Append("</script>");
//Check to see if the startup script is already registered
if (!cs.IsClientScriptBlockRegistered(cstype, csname))
...{
cs.RegisterStartupScript(cstype, csname, cstext.ToString(), true);
}
}
/**//// <summary>
/// 下载文件
/// </summary>
/// <param name="DstrFileName"></param>
/// <param name="YstrUrl"></param>
/// <returns></returns>
public static bool DownLoadFile(string DstrFileName, string YstrUrl)
...{
//打开上次下载的文件或新建文件
long lStartPos = 0;
System.IO.FileStream fs;
if (System.IO.File.Exists(DstrFileName))
...{
fs = System.IO.File.OpenWrite(DstrFileName);
lStartPos = fs.Length;
fs.Seek(lStartPos, System.IO.SeekOrigin.Current); //移动文件流中的当前指针
}
else
...{
fs = new System.IO.FileStream(DstrFileName, System.IO.FileMode.Create);
lStartPos = 0;
}
//打开网络连接
try
...{
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(YstrUrl);
if (lStartPos > 0)
request.AddRange((int)lStartPos); //设置Range值
//向服务器请求,获得服务器回应数据流
System.IO.Stream ns = request.GetResponse().GetResponseStream();
byte[] nbytes = new byte[512];
int nReadSize = 0;
nReadSize = ns.Read(nbytes, 0, 512);
while (nReadSize > 0)
...{
fs.Write(nbytes, 0, nReadSize);
nReadSize = ns.Read(nbytes, 0, 512);
}
fs.Close();
ns.Close();
//("下载完成");
return true;
}
catch
...{
fs.Close();
return false;
}
}
}
}
- .CS中的JavaScript
- CS 中的键位设置
- 实现cs中的控制台
- CS中的九种人
- 再续cs中的委托
- PhotoshopCS中的CS是什么意思?
- javascript与cs代码互访
- javascript与cs代码互访
- CS:APP中的tsh示例
- 汇编中的CS和IP
- zmq 中的cs 模式总结
- 如何让Javascript脚本执行CS函数。
- 斯坦福CS基础课程教JavaScript
- .net中javascript与后台cs通讯
- .net .cs文件中执行javascript脚本
- CS..........................
- cs
- cs
- 如果让我重做一次研究生
- Eclipse的Adapter机制
- SSDT Hook的妙用-对抗ring0 inline hook
- 从电影《Pulp Fiction》片段看精简敏捷开发
- ASP.NET开发OA的例子(源代码)
- .CS中的JavaScript
- 上个月一位朋友买到翻新N80手机 淘宝充斥奸商假货 【该奸商为四钻】
- WinRunner测试设计(1)
- 公文流转系统(C#)
- VC中使用ADO进行数据库开发的一些资料的整理
- WinRunner测试设计(2)
- 每一天都有让你感动的事
- 职场综合素质从何来?
- 远程控制软件