在整理一套OA发现的有些东西
我会陆续拿出给大家
希望对大家有用!
)
using System;
using SystemWeb;
using SystemWebUIHtmlControls ;
using SystemWebUI;
namespace WebJScript
{
/// <summary>
/// 提供向页面输出客户端代码实现特殊功能的方法
/// </summary>
/// <remarks>
/// </remarks>
public class JScript
{
public static void AlertAndRedirect(string messagestring toURL)
{
string js = <script language=javascript>alert({})windowlocationreplace({})</script>;
HttpContextCurrentResponseWrite(stringFormat(jsmessage toURL))
}
/// <summary>
/// 向客户端发送函数KendoPostBack(eventTarget eventArgument)
/// 服务器端可接收__EVENTTARGET__EVENTARGUMENT的值
/// </summary>
/// <param name=page>SystemWebUIPage 一般为this</param>
public static void JscriptSender(SystemWebUIPage page)
{
pageRegisterHiddenField(__EVENTTARGET)
pageRegisterHiddenField(__EVENTARGUMENT)
string s = @
<script language=Javascript>
function KendoPostBack(eventTarget eventArgument)
{
var theform = documentforms[];
theform__EVENTTARGETvalue = eventTarget;
theform__EVENTARGUMENTvalue = eventArgument;
theformsubmit()
}
</script>;
pageRegisterStartupScript(sdss)
}
/// <summary>
/// 弹出JavaScript小窗口
/// </summary>
/// <param name=js>窗口信息</param>
public static void Alert(string message)
{
message = StringUtilDeleteUnVisibleChar(message)
string js=@<Script language=JavaScript>
alert(+ message +)</Script>;
HttpContextCurrentResponseWrite(js)
}
public static void Alert(object message)
{
string js=@<Script language=JavaScript>
alert({})
</Script>;
HttpContextCurrentResponseWrite(stringFormat(jsmessageToString()))
}
public static void RtnRltMsgbox(object messagestring strWinCtrl)
{
string js = @<Script language=JavaScript>
strWinCtrl = true;
strWinCtrl = if(!confirm(+ message +))return false;</Script>;
HttpContextCurrentResponseWrite(stringFormat(jsmessageToString()))
}
/// <summary>
/// 回到历史页面
/// </summary>
/// <param name=value>/</param>
public static void GoHistory(int value)
{
string js=@<Script language=JavaScript>
historygo({})
</Script>;
HttpContextCurrentResponseWrite(stringFormat(jsvalue))
}
/// <summary>
/// 关闭当前窗口
/// </summary>
public static void CloseWindow()
{
string js=@<Script language=JavaScript>
windowclose()
</Script>;
HttpContextCurrentResponseWrite(js)
HttpContextCurrentResponseEnd()
}
/// <summary>
/// 刷新父窗口
/// </summary>
public static void RefreshParent()
{
string js=@<Script language=JavaScript>
parentlocationreload()
</Script>;
HttpContextCurrentResponseWrite(js)
}
/// <summary>
/// 格式化为JS可解释的字符串
/// </summary>
/// <param name=s></param>
/// <returns></returns>
public static string JSStringFormat(string s)
{
return sReplace(\r\\r)Replace(\n\\n)Replace(\\)Replace(\\\\)
}
/// <summary>
/// 刷新打开窗口
/// </summary>
public static void RefreshOpener()
{
string js=@<Script language=JavaScript>
openerlocationreload()
</Script>;
HttpContextCurrentResponseWrite(js)
}
/// <summary>
/// 打开窗口
/// </summary>
/// <param name=url></param>
public static void OpenWebForm(string url)
{
/*……*/
/*修改目的 新开页面去掉ie的菜单… */
string js=@<Script language=JavaScript>
//windowopen(+url+@)
windowopen(+url+@height=width=top=left=location=nomenubar=noresizable=yesscrollbars=yesstatus=yestitlebar=notoolbar=nodirectories=no)
</Script>;
/*结束*/
/*……*/
HttpContextCurrentResponseWrite(js)
}
public static void OpenWebForm(string urlstring namestring future)
{
string js=@<Script language=JavaScript>
windowopen(+url+@+name+@+future+@)
</Script>;
HttpContextCurrentResponseWrite(js)
}
public static void OpenWebForm(string urlstring formName)
{
/*……*/
/*修改目的 新开页面去掉ie的菜单… */
/*注释内容 */
/*开始*/
string js=@<Script language=JavaScript>
windowopen(+url+@+formName+@height=width=top=left=location=nomenubar=noresizable=yesscrollbars=yesstatus=yestitlebar=notoolbar=nodirectories=no)
</Script>;
/*结束*/
/*……*/
HttpContextCurrentResponseWrite(js)
}
/// <summary>
/// 函数名OpenWebForm
/// 功能描述打开WEB窗口
/// </summary>
/// <param name=url>WEB窗口</param>
/// <param name=isFullScreen>是否全屏幕</param>
public static void OpenWebForm(string urlbool isFullScreen)
{
string js=@<Script language=JavaScript>;
if(isFullScreen)
{
js+=var iWidth = ;;
js+=var iHeight = ;;
js+=iWidth=windowscreenavailWidth;;
js+=iHeight=windowscreenavailHeight;;
js+=var szFeatures =width= + iWidth + height= + iHeight + top=left=location=nomenubar=noresizable=yesscrollbars=yesstatus=yestitlebar=notoolbar=nodirectories=no;;
js+=windowopen(+url+@szFeatures);
}
else
{
js+=windowopen(+url+@height=width=top=left=location=nomenubar=noresizable=yesscrollbars=yesstatus=yestitlebar=notoolbar=nodirectories=no);
}
js+=</Script>;
HttpContextCurrentResponseWrite(js)
}
/// <summary>
/// 转向Url制定的页面
/// </summary>
/// <param name=url></param>
public static void JavaScriptLocationHref(string url)
{
string js=@<Script language=JavaScript>
windowlocationreplace({})
</Script>;
js=stringFormat(jsurl)
HttpContextCurrentResponseWrite(js)
}
/// <summary>
/// 指定的框架页面转换
/// </summary>
/// <param name=FrameName></param>
/// <param name=url></param>
public static void JavaScriptFrameHref(string FrameNamestring url)
{
string js=@<Script language=JavaScript>
@objlocationreplace({})
</Script>;
js = jsReplace(@objFrameName )
js=stringFormat(jsurl)
HttpContextCurrentResponseWrite(js)
}
/// <summary>
///重置页面
/// </summary>
public static void JavaScriptResetPage(string strRows)
{
string js=@<Script language=JavaScript>
windowparentCenterFramerows=+strRows+;</Script>;
HttpContextCurrentResponseWrite(js)
}
/// <summary>
/// 函数名JavaScriptSetCookie
/// 功能描述客户端方法设置Cookie
/// </summary>
/// <param name=strName>Cookie名</param>
/// <param name=strValue>Cookie值</param>
public static void JavaScriptSetCookie(string strNamestring strValue)
{
string js=@<script language=Javascript>
var the_cookie = +strName+=+strValue+@
var dateexpire = Tuesday Dec :: GMT;
//okie = the_cookie;//写入Cookie<BR>} <BR>
okie = the_cookie + ; expires=+dateexpire;
</script>;
HttpContextCurrentResponseWrite(js)
}
/// <summary>
/// 函数名GotoParentWindow
/// 功能描述返回父窗口
/// </summary>
/// <param name=parentWindowUrl>父窗口</param>
public static void GotoParentWindow(string parentWindowUrl)
{
string js=@<Script language=JavaScript>
thisparentlocationreplace(+parentWindowUrl+)</Script>;
HttpContextCurrentResponseWrite(js)
}
/// <summary>
/// 函数名ReplaceParentWindow
/// 功能描述替换父窗口
/// </summary>
/// <param name=parentWindowUrl>父窗口</param>
/// <param name=caption>窗口提示</param>
/// <param name=future>窗口特征参数</param>
public static void ReplaceParentWindow(string parentWindowUrlstring captionstring future)
{
string js=;
if(future!=null&&futureTrim()!=)
{
js=@<script language=javascript>thisparentlocationreplace(+parentWindowUrl++caption++future+)</script>;
}
else
{
js=@<script language=javascript>var iWidth = ;var iHeight = ;iWidth=windowscreenavailWidth;iHeight=windowscreenavailHeight;
var szFeatures = dialogWidth:+iWidth+;dialogHeight:+iHeight+;dialogLeft:px;dialogTop:px;center:yes;help=no;resizable:on;status:on;scroll=yes;thisparentlocationreplace(+parentWindowUrl++caption+szFeatures)</script>;
}
HttpContextCurrentResponseWrite(js)
}
/// <summary>
/// 函数名ReplaceOpenerWindow
/// 功能描述替换当前窗体的打开窗口
/// </summary>
/// <param name=openerWindowUrl>当前窗体的打开窗口</param>
public static void ReplaceOpenerWindow(string openerWindowUrl)
{
string js=@<Script language=JavaScript>
windowopenerlocationreplace(+openerWindowUrl+)</Script>;
HttpContextCurrentResponseWrite(js)
}
/// <summary>
/// 函数名ReplaceOpenerParentWindow
/// 功能描述替换当前窗体的打开窗口的父窗口
/// </summary>
/// <param name=openerWindowUrl>当前窗体的打开窗口的父窗口</param>
public static void ReplaceOpenerParentFrame(string frameNamestring frameWindowUrl)
{
string js=@<Script language=JavaScript>
windowopenerparent + frameName + locationreplace(+frameWindowUrl+)</Script>;
HttpContextCurrentResponseWrite(js)
}
/// <summary>
/// 函数名ReplaceOpenerParentWindow
/// 功能描述替换当前窗体的打开窗口的父窗口
/// </summary>
/// <param name=openerWindowUrl>当前窗体的打开窗口的父窗口</param>
public static void ReplaceOpenerParentWindow(string openerParentWindowUrl)
{
string js=@<Script language=JavaScript>
windowopenerparentlocationreplace(+openerParentWindowUrl+)</Script>;
HttpContextCurrentResponseWrite(js)
}
/// <summary>
/// 函数名CloseParentWindow
/// 功能描述关闭窗口
/// </summary>
public static void CloseParentWindow()
{
string js=@<Script language=JavaScript>
windowparentclose()
</Script>;
HttpContextCurrentResponseWrite(js)
}
public static void CloSEOpenerWindow()
{
string js=@<Script language=JavaScript>
windowopenerclose()
</Script>;
HttpContextCurrentResponseWrite(js)
}
/// <summary>
/// 函数名ShowModalDialogJavascript
/// 功能描述返回打开模式窗口的脚本
/// </summary>
/// <param name=webFormUrl></param>
/// <returns></returns>
public static string ShowModalDialogJavascript(string webFormUrl)
{
string js=@<script language=javascript>
var iWidth = ;
var iHeight = ;
iWidth=windowscreenavailWidth;
iHeight=windowscreenavailHeight;
var szFeatures = dialogWidth:+iWidth+;dialogHeight:+iHeight+;dialogLeft:px;dialogTop:px;center:yes;help=no;resizable:on;status:on;scroll=yes;
showModalDialog(+webFormUrl+szFeatures)</script>;
return js;
}
public static string ShowModalDialogJavascript(string webFormUrlstring features)
{
string js=@<script language=javascript>
showModalDialog(+webFormUrl++features+)</script>;
return js;
}
/// <summary>
/// 函数名ShowModalDialogWindow
/// 功能描述打开模式窗口
/// </summary>
/// <param name=webFormUrl></param>
/// <returns></returns>
public static void ShowModalDialogWindow(string webFormUrl)
{
string js=ShowModalDialogJavascript(webFormUrl)
HttpContextCurrentResponseWrite(js)
}
public static void ShowModalDialogWindow(string webFormUrlstring features)
{
string js=ShowModalDialogJavascript(webFormUrlfeatures)
HttpContextCurrentResponseWrite(js)
}
public static void ShowModalDialogWindow(string webFormUrlint widthint heightint topint left)
{
string features = dialogWidth:+widthToString() + px
+;dialogHeight: + heightToString() + px
+;dialogLeft: + leftToString() + px
+;dialogTop: + topToString() + px
+;center:yes;help=no;resizable:no;status:no;scroll=no;
ShowModalDialogWindow(webFormUrlfeatures)
}
public static void SetHtmlElementValue(string formNamestring elementNamestring elementValue)
{
string js=@<Script language=JavaScript>if(document+formName+ + elementName +!=null){document+formName+ + elementName +value =+ elementValue +;}</Script>;
HttpContextCurrentResponseWrite(js)
}
}
}