using System.Web;
using System.Web.UI;
using System.Text;
public abstract class JS
{
/**////
/// 客户端打开窗口
///
///
public static void OpenWindow(string strUrl)
{
HttpContext.Current.Response.Write("");
}
/**////
/// 输出自定义脚本信息
///
/// 当前页面指针,一般为this
/// 输出脚本
public static void ResponseScript(System.Web.UI.Page page,string script)
{
page.RegisterStartupScript("message","");
}
/**////
/// 显示消息提示对话框,并进行页面跳转
///
/// 当前页面指针,一般为this
/// 提示信息
/// 跳转的目标URL
public static void ShowAndRedirect(System.Web.UI.Page page,string msg,string url)
{
StringBuilder Builder=new StringBuilder();
Builder.Append("");
page.RegisterStartupScript("message",Builder.ToString());
}
public static void ShowConfirm(System.Web.UI.WebControls.WebControl Control,string msg)
{
Control.Attributes.Add("onclick", "return confirm('" + msg + "');") ;
}
/**////
/// 清空所有panel里面的textbox内容
///
///
public static void clearAll(System.Web.UI.WebControls.Panel pan)
{
foreach (Control panl in pan.Controls )
{
if(panl.GetType().ToString()=="System.Web.UI.WebControls.TextBox")
{
((System.Web.UI.WebControls.TextBox)panl).Text="";
}
}
}
/**////
/// 窗体加载以后探出对话框
///
public static void Alert(string msg)
{
Page pages;
pages= HttpContext.Current.Handler as System.Web.UI.Page;
msg=msg.Replace("'","");
msg=msg.Replace("\"","");
msg=msg.Replace("\n",@"\n").Replace("\r",@"\r").Replace("\"",@"\""") ;
pages.Controls.Add(new System.Web.UI.LiteralControl(""));
}
/**////
/// 窗体没有加载的时候如pageload的时候探出对话框
///
public static void Alert_none(string msg)
{
Page pages;
pages= HttpContext.Current.Handler as System.Web.UI.Page;
msg=msg.Replace("'","");
msg=msg.Replace("\"","");
msg=msg.Replace("\n",@"\n").Replace("\r",@"\r").Replace("\"",@"\""") ;
string retu = " alert('" + msg + "');";
ClientWrite2( retu);
}
/**////
/// 加载以后写自己的脚本
///
///
///
public static void ClientWrite(string yourJs)
{
Page pages;
pages= HttpContext.Current.Handler as System.Web.UI.Page;
pages.Controls.Add(new System.Web.UI.LiteralControl(""));
}
/**////
/// 加载以前写自己的脚本
///
///
///
public static void ClientWrite2(string yourJs)
{
Page pages;
pages= HttpContext.Current.Handler as System.Web.UI.Page;
pages.Response.Write("");
}
/**////
/// 得到刷新界面的字符串
///
///
public static string RefreshWin()
{
return "window.location=window.location.href;";
}
/**////
/// 打开小窗体
///
///
///
///
///
///
public static void OpenLittleWindow(string url,int width,int height,int top,int left)
{
string str;
str = "javascript:var popup;popup=window.open('{url}',null,'scrollbars=yes,status=no,width={width},height={height},top={top},left={left}');popup.opener=self.opener;self.close();";
str = str.Replace("{width}", width.ToString());
str = str.Replace("{height}", height.ToString());
str = str.Replace("{top}", top.ToString());
str = str.Replace("{left}", left.ToString());
str=str.Replace("{url}",url);
}
/**////
/// 回车-〉tab
///
///
public static void ToTab()
{
Page page;
page= HttpContext.Current.Handler as System.Web.UI.Page;
System.Text.StringBuilder scriptFunction=new StringBuilder();
scriptFunction.Append("");
page.RegisterStartupScript("totab", scriptFunction.ToString());
}
/**////
/// tab->enter
///
///
public static void tabToEnter()
{
Page page;
page= HttpContext.Current.Handler as System.Web.UI.Page;
System.Text.StringBuilder scriptFunction=new StringBuilder();
scriptFunction.Append("");
page.RegisterStartupScript("switch", scriptFunction.ToString());
}
/**////
/// attachEvent
///
///
///
public static void attachEvent(Control[] controlToFocus)
{
Page page;
page= HttpContext.Current.Handler as System.Web.UI.Page;
System.Text.StringBuilder scriptFunction=new StringBuilder();
string scriptClientId;
scriptFunction.Append("");
page.RegisterStartupScript("attach", scriptFunction.ToString());
}
/**////
///
///
///
///
///
///
public static void AttachEvent(Control[] controlToFocus,string eventStr,string FuncStr)
{
Page page;
page= HttpContext.Current.Handler as System.Web.UI.Page;
System.Text.StringBuilder scriptFunction=new StringBuilder();
string scriptClientId;
scriptFunction.Append("");
page.RegisterStartupScript("attach2", scriptFunction.ToString());
}
/**////
///
///
///
public static void NumOnlyFun()
{
Page page;
page= HttpContext.Current.Handler as System.Web.UI.Page;
System.Text.StringBuilder scriptFunction=new StringBuilder();
scriptFunction.Append("");
page.RegisterStartupScript("numonly", scriptFunction.ToString());
}
}
本文作者:9who 来源:http://www.cnblogs.com/9who/
CIO之家 www.ciozj.com 微信公众号:imciow