大家好,又见面了,我是你们的朋友全栈君。
一些客户端脚本
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace MyBlog.WEB
{
public class PageBase : System.Web.UI.Page
{
/// <summary>
/// MD5加密
/// </summary>
/// <param name=”sInputString”>需要加密的字符串</param>
/// <returns>加密后字符串</returns>
public static string HashString(string sInputString)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sInputString, “MD5”);
}
/// <summary>
/// MessageBox提示框
/// </summary>
/// <param name=”Message”>提示信息</param>
public void MsgBox(string Message)
{
ClientScript.RegisterStartupScript(this.GetType(), “”, “<script type=’text/javascript’>alert(‘” + Message + “‘);</script>”);
return;
}
/// <summary>
/// MessageBox提示并转向新页面
/// </summary>
/// <param name=”Message”>提示信息</param>
/// <param name=”URL”>跳转的路径</param>
public void MsgBox(string Message, string URL)
{
ClientScript.RegisterStartupScript(this.GetType(), “”, “<script type=’text/javascript’>alert(‘” + Message + “‘);window.location='” + URL + “‘;</script>”);
return;
}
/// <summary>
/// 弹出新窗口
/// </summary>
/// <param name=”pagePath”>页面路径</param>
/// <param name=”winName”>新窗口名称</param>
/// <param name=”winWidth”>新窗口宽度</param>
/// <param name=”winHeight”>新窗口高度</param>
public void openNewWin(string pagePath, string winName, int winWidth, int winHeight)
{
ClientScript.RegisterStartupScript(this.GetType(), “”, “<script type=’text/javascript’>window.open(‘” + pagePath + “‘,'” + winName + “‘,’toolbar=no,menubar=no,titlebar=no,directories=no,resizable=no,scroll=yes,status=no,fullscreen=no,center=yes,width=” + winWidth + “,height=” + winHeight + “‘);</script>”);
return;
}
/// <summary>
/// 弹出模态窗口
/// </summary>
/// <param name=”pagePath”>页面路径</param>
/// <param name=”winWidth”>窗口宽度</param>
/// <param name=”winHeight”>窗口高度</param>
public void openModelWin(string pagePath, int winWidth, int winHeight)
{
string temp;
temp = @”<script language=’javascript’>”;
temp += (@” var sPath ='” + pagePath + “‘;”);
temp += (@” strFeatures =’dialogWidth=” + winWidth + “px;dialogHeight=” + winHeight + “px;center=yes;scroll=no;help=no;status: No’;”);
temp += (@” var returnvalue = window.showModalDialog(sPath,’brower’,strFeatures);”);
temp += (@”</script>”);
ClientScript.RegisterStartupScript(this.GetType(), “message”, temp);
}
/// <summary>
/// 弹出控制父窗口的模态窗口
/// </summary>
/// <param name=”pagePath”>页面路径</param>
/// <param name=”winWidth”>窗口宽度</param>
/// <param name=”winHeight”>窗口高度</param>
/// <param name=”frameshref”>控制父窗口路径</param>
public void openModelWin(string pagepath, int width, int height, string frameshref)
{
string temp = @”<script language=’javascript’>”;
temp += (@” var sPath ='” + pagepath + “‘;”);
temp += (@” strFeatures =’dialogWidth=” + width + “px;dialogHeight=” + height + “px;center=yes;scroll=no;help=no;status=no’;”);
temp += (@” var returnvalue = window.showModalDialog(sPath,’brower’,strFeatures);”);
temp += (@” window.location.href = ‘” + frameshref + “‘;”);
temp += (@”</script>”);
ClientScript.RegisterStartupScript(this.GetType(), “message”, temp);
}
/// <summary>
/// 关闭本窗口
/// </summary>
public void CloseWin()
{
ClientScript.RegisterStartupScript(this.GetType(), “”, “<script type=’text/javascript’>window.opener=null;window.close();</script>”);
return;
}
/// <summary>
/// 弹出提示信息,并关闭本窗口
/// <param name=”Words”>弹出提示信息内容</param>
/// </summary>
public void CloseWin(string Words)
{
ClientScript.RegisterStartupScript(this.GetType(), “”, “<script type=’text/javascript’>alert(‘”+Words+”‘);window.opener=null;window.close();</script>”);
return;
}
/// <summary>
/// 关闭本窗口并,重新加载父窗口.
/// </summary>
/// <param name=”URL”>父窗口要加载的URL</param>
public void reLoadParentAndClose(string URL)
{
ClientScript.RegisterStartupScript(this.GetType(), “”, “<script type=’text/javascript’>window.opener.location='” + URL + “‘;window.close();</script>”);
return;
}
/// <summary>
/// 显示提示信息,关闭本窗口并,重新加载父窗口.
/// </summary>
/// <param name=”Words”>提示消息内容</param>
/// <param name=”URL”>父窗口要加载的URL</param>
public void ShowWords_reLoadParentAndClose(string Words,string URL)
{
ClientScript.RegisterStartupScript(this.GetType(), “”, “<script type=’text/javascript’>alert(‘” + Words
+ “‘); window.opener.location='” + URL + “‘;window.close();</script>”);
return;
}
/// <summary>
/// 获取客户端IP
/// </summary>
/// <returns></returns>
public string GetClientIP()
{
string result = HttpContext.Current.Request.ServerVariables[“HTTP_X_FORWARDED_FOR”];
if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.ServerVariables[“REMOTE_ADDR”];
}
if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.UserHostAddress;
}
return result;
}
/// <summary>
/// 获取Session值
/// </summary>
/// <param name=”SessionID”>要获取的Session值</param>
/// <returns></returns>
public string GetSession(string SessionID)
{
string restr = “unkown”;
try
{
restr = Session[SessionID].ToString();
}
catch
{
}
if (restr == “unkown” && restr == null && restr == “”)
{
Response.Redirect(“/Error.aspx?Type=NoPopedom”);
}
return restr;
}
/// <summary>
/// 写Cookie
/// </summary>
/// <param name=”CookiesName”>Cookie集名称</param>
/// <param name=”name”>Cookie名</param>
/// <param name=”Value”>值</param>
public void WritCookie(string CookiesName, string name, string Value)
{
HttpCookie cookie = new HttpCookie(CookiesName);
cookie.Values.Add(name, Value);
Response.AppendCookie(cookie);
}
/// <summary>
/// 获取Cookie
/// </summary>
/// <param name=”CookiesName”>Cookie集名称</param>
/// <param name=”name”>Cookie名</param>
/// <param name=”Value”>值</param>
public string GetCookie(string CookiesName, string name)
{
string value = string.Empty;
try
{
HttpCookie cookie = Request.Cookies[CookiesName];
value = cookie.Values[name];
}
catch
{
Response.Redirect(“/Error.aspx?Type=GetCookie”);
}
return value;
}
}
}
转载于:https://www.cnblogs.com/softwareking/archive/2011/03/19/1988570.html
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/162301.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...