OAセットを整理しているときに発見したことのいくつかを共有します。皆さんのお役に立てば幸いです! :)
システムを使用します。
System.Web を使用します。
System.Web.UI.HtmlControls を使用します。
System.Web.UI
名前空間 Web.JScript
を使用します。
{
/// <概要>
/// 特別な関数を実装するためにクライアント側のコードをページに出力するメソッドを提供します。
/// </概要>
/// <備考>
/// </remarks>
パブリック クラス JScript
{
public static void AlertAndRedirect(文字列メッセージ,文字列 toURL)
{
string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
HttpContext.Current.Response.Write(string.Format(js,message,toURL));
}
/// <概要>
/// 関数 KendoPostBack(eventTarget,eventArgument) をクライアントに送信します
/// サーバーは__EVENTTARGET、__EVENTARGUMENTの値を受け取ることができます
/// </概要>
/// <param name="page">System.Web.UI.Page は通常これです</param>
public static void JscriptSender(System.Web.UI.Page ページ)
{
page.RegisterHiddenField("__EVENTTARGET","");
page.RegisterHiddenField("__EVENTARGUMENT","");
文字列 s = @"
<スクリプト言語=JavaScript>
関数 KendoPostBack(eventTarget,eventArgument)
{
var theform = document.forms[0];
theform.__EVENTTARGET.value = イベントターゲット;
theform.__EVENTARGUMENT.value = イベント引数;
theform.submit();
}
</script>";
page.RegisterStartupScript("sds",s);
}
/// <概要>
/// 小さな JavaScript ウィンドウをポップアップ表示します
/// </概要>
/// <param name="js">ウィンドウ情報</param>
public static void Alert(文字列メッセージ)
{
メッセージ = StringUtil.DeleteUnVisibleChar(メッセージ);
string js=@"<スクリプト言語='JavaScript'>
alert('"+メッセージ +"');</Script>";
HttpContext.Current.Response.Write(js);
}
public static void Alert(オブジェクトメッセージ)
{
string js=@"<スクリプト言語='JavaScript'>
アラート('{0}');
</スクリプト>";
HttpContext.Current.Response.Write(string.Format(js,message.ToString()));
public static void RtnRltMsgbox(オブジェクトメッセージ,string strWinCtrl
)
{
string js = @"<スクリプト言語='JavaScript'>
strWinCtrl = true;
strWinCtrl = if(!confirm('"+ message +"'))return false;</Script>";
HttpContext.Current.Response.Write(string.Format(js,message.ToString()));
}
/// <概要>
/// 履歴ページに戻る
/// </概要>
/// <param name="value">-1/1</param>
public static void GoHistory(int 値)
{
string js=@"<スクリプト言語='JavaScript'>
History.go({0});
</スクリプト>";
HttpContext.Current.Response.Write(string.Format(js,value));
}
/// <概要>
/// 現在のウィンドウを閉じる
/// </概要>
public static void CloseWindow()
{
string js=@"<スクリプト言語='JavaScript'>
window.close();
</スクリプト>";
HttpContext.Current.Response.Write(js);
HttpContext.Current.Response.End();
}
/// <概要>
/// 親ウィンドウを更新します
/// </概要>
public static void RefreshParent()
{
string js=@"<スクリプト言語='JavaScript'>
親の場所.reload();
</スクリプト>";
HttpContext.Current.Response.Write(js);
}
/// <概要>
/// JS で解釈可能な文字列にフォーマットされる
/// </概要>
/// <param name="s"></param>
/// <戻り値></戻り値>
パブリック静的文字列 JSStringFormat(string s)
{
return s.Replace( "r"," \r").Replace("n","\n").Replace("'","\'").Replace(""" ,"\ "");
}
/// <概要>
/// 開いているウィンドウを更新します
/// </概要>
public static void RefreshOpener()
{
string js=@"<スクリプト言語='JavaScript'>
opener.location.reload();
</スクリプト>";
HttpContext.Current.Response.Write(js);
}
/// <概要>
/// ウィンドウを開く
/// </概要>
/// <param name="url"></param>
public static void OpenWebForm(string url)
{
/*………………………………………………………………………………*/
/*変更の目的: 新しいページから ie メニューを削除します。 。 。 */
string js=@"<スクリプト言語='JavaScript'>
//window.open('" +url+@"' );
window.open('" +url+@"','','height=0,width=0,top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=はい、タイトルバー = いいえ、ツールバー = いいえ、ディレクトリ = いいえ' );
</スクリプト>";
/*仕上げる*/
/*………………………………………………………………………………*/
HttpContext.Current.Response.Write(js);
}
public static void OpenWebForm(string URL,string name,string future)
{
string js=@"<スクリプト言語='JavaScript'>
window.open('" +url+@"','"+name+@"','"+future+@"' )
</スクリプト>";
HttpContext.Current.Response.Write(js);
}
public static void OpenWebForm(string URL,string formName)
{
/*………………………………………………………………………………*/
/*変更の目的: 新しいページから ie メニューを削除します。 。 。 */
/*コメント内容: */
/*始める*/
string js=@"<スクリプト言語='JavaScript'>
window.open('" +url+@"','"+formName+@"','height=0,width=0,top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars =はい、ステータス=はい、タイトルバー=いいえ、ツールバー=いいえ、ディレクトリ=いいえ' );
</スクリプト>";
/*仕上げる*/
/*……………………………………………………………………………………………………*/
HttpContext.Current.Response.書き込み(js);
}
/// <概要>
/// 関数名: OpenWebForm
/// 機能説明: WEBウィンドウを開く
/// </概要>
/// <param name="url">WEB ウィンドウ</param>
/// <param name="isFullScreen">全画面かどうか</param>
public static void OpenWebForm(string url,bool isFullScreen)
{
文字列js=@"<スクリプト言語='JavaScript'>";
if(isフルスクリーン)
{
js+="var iWidth = 0;";
js+="var iHeight = 0;";
js+="iWidth=window.screen.availWidth-10;";
js+="iHeight=window.screen.availHeight-50;";
js+="var sz features ='width=' + iWidth + ',height=' + iHeight + ',top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes 、タイトルバー = いいえ、ツールバー = いいえ、ディレクトリ = いいえ';";
js+="window.open('" +url+@"','',sz特徴);";
}
それ以外
{
js+="window.open('" +url+@"','','height=0,width=0,top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes ,ステータス=はい、タイトルバー=いいえ、ツールバー=いいえ、ディレクトリ=いいえ' );";
}
js+="</スクリプト>";
HttpContext.Current.Response.Write(js);
}
/// <概要>
/// URLで指定されたページに移動します
/// </概要>
/// <param name="url"></param>
public static void JavaScriptLocationHref(string url)
{
string js=@"<スクリプト言語='JavaScript'>
window.location.replace('{0}');
</スクリプト>";
js=string.Format(js,url);
HttpContext.Current.Response.Write(js);
}
/// <概要>
/// 指定されたフレームページ変換
/// </概要>
/// <param name="フレーム名"></param>
/// <param name="url"></param>
public static void JavaScriptFrameHref(string FrameName,string url)
{
string js=@"<スクリプト言語='JavaScript'>
@obj.location.replace(""{0}"");
</スクリプト>";
js = js.Replace("@obj",フレーム名 );
js=string.Format(js,url);
HttpContext.Current.Response.Write(js);
}
/// <概要>
///ページをリセット
/// </概要>
public static void JavaScriptResetPage(string strRows)
{
string js=@"<スクリプト言語='JavaScript'>
window.parent.CenterFrame.rows='"+strRows+"';</Script>";
HttpContext.Current.Response.Write(js);
}
/// <概要>
/// 関数名: JavaScriptSetCookie
/// 関数の説明: クライアント メソッドは Cookie を設定します
/// </概要>
/// <param name="strName">クッキー名</param>
/// <param name="strValue">Cookie 値</param>
public static void JavaScriptSetCookie(string strName,string strValue)
{
string js=@"<スクリプト言語=Javascript>
var the_cookie = '"+strName+"=" +strValue+@"'
var dateexpire = '2020 年 12 月 1 日火曜日 12:00:00 GMT';
//document.cookie = the_cookie;//Cookie を書き込みます<BR>} <BR>
document.cookie = the_cookie + ' 期限切れ='+日付期限切れ;
</script>";
HttpContext.Current.Response.Write(js);
}
/// <概要>
/// 関数名: GotoParentWindow
/// 関数説明: 親ウィンドウに戻る
/// </概要>
/// <param name="parentWindowUrl">親ウィンドウ</param>
public static void GotoParentWindow(stringparentWindowUrl)
{
string js=@"<スクリプト言語='JavaScript'>
this.parent.location.replace('"+parentWindowUrl+"');</Script>";
HttpContext.Current.Response.Write(js);
}
/// <概要>
/// 関数名:ReplaceParentWindow
/// 関数の説明: 親ウィンドウを置き換えます
/// </概要>
/// <param name="parentWindowUrl">親ウィンドウ</param>
/// <param name="caption">ウィンドウプロンプト</param>
/// <param name="future">ウィンドウ機能パラメータ</param>
public static void ReplaceParentWindow(stringparentWindowUrl,stringcaption,stringfuture)
{
文字列js="";
if(future!=null&&future.Trim()!="")
{
js=@"<script language=javascript>this.parent.location.replace('"+parentWindowUrl+"','"+caption+"','"+future+"');</script>";
}
それ以外
{
js=@"<script language=javascript>var iWidth = 0;var iHeight = 0;iWidth=window.screen.availWidth-10;iHeight=window.screen.availHeight-50;
var szFunction = 'dialogWidth:'+iWidth+';dialogHeight:'+iHeight+';dialogLeft:0px;dialogTop:0px;center:yes;help=no;resizable:on;status:on;scroll=yes';this.parent .location.replace('"+parentWindowUrl+"','"+caption+"',sz features);</script>";
HttpContext.Current.Response.Write(js)
;
}
/// <概要>
/// 関数名:ReplaceOpenerWindow
/// 関数の説明: 現在のフォームの開いているウィンドウを置き換えます
/// </概要>
/// <param name="openerWindowUrl">現在のフォームの開いているウィンドウ</param>
public static void ReplaceOpenerWindow(string openerWindowUrl)
{
string js=@"<スクリプト言語='JavaScript'>
window.opener.location.replace('"+openerWindowUrl+"');</Script>";
HttpContext.Current.Response.Write(js);
}
/// <概要>
/// 関数名:ReplaceOpenerParentWindow
/// 関数の説明: 現在のフォームで開いているウィンドウの親ウィンドウを置き換えます。
/// </概要>
/// <param name="openerWindowUrl">現在のフォームで開いているウィンドウの親ウィンドウ</param>
public static void ReplaceOpenerParentFrame(string FrameName,string FrameWindowUrl)
{
string js=@"<スクリプト言語='JavaScript'>
window.opener.parent." + FrameName + ".location.replace('"+frameWindowUrl+"');</Script>";
HttpContext.Current.Response.Write(js);
}
/// <概要>
/// 関数名:ReplaceOpenerParentWindow
/// 関数の説明: 現在のフォームで開いているウィンドウの親ウィンドウを置き換えます。
/// </概要>
/// <param name="openerWindowUrl">現在のフォームで開いているウィンドウの親ウィンドウ</param>
public static void ReplaceOpenerParentWindow(string openerParentWindowUrl)
{
string js=@"<スクリプト言語='JavaScript'>
window.opener.parent.location.replace('"+openerParentWindowUrl+"');</Script>";
HttpContext.Current.Response.Write(js);
}
/// <概要>
/// 関数名: CloseParentWindow
/// 関数の説明: ウィンドウを閉じる
/// </概要>
public static void CloseParentWindow()
{
string js=@"<スクリプト言語='JavaScript'>
window.parent.close();
</スクリプト>";
HttpContext.Current.Response.Write(js);
}
public static void CloseOpenerWindow()
{
string js=@"<スクリプト言語='JavaScript'>
window.opener.close();
</スクリプト>";
HttpContext.Current.Response.Write(js);
}
/// <概要>
/// 関数名: ShowModalDialogJavascript
/// 関数の説明: モーダル ウィンドウを開くスクリプトを返します。
/// </概要>
/// <param name="webFormUrl"></param>
/// <戻り値></戻り値>
public static string ShowModalDialogJavascript(string webFormUrl)
{
string js=@"<スクリプト言語=javascript>
var iWidth = 0;
var iHeight = 0;
iWidth=window.screen.availWidth-10;
iHeight=window.screen.availHeight-50;
var szFunction = 'dialogWidth:'+iWidth+';dialogHeight:'+iHeight+';dialogLeft:0px;dialogTop:0px;center:yes;help=no;resizable:on;status:on;scroll=yes';
showModalDialog('"+webFormUrl+"','',sz features);</script>";
jsを返します。
public static string ShowModalDialogJavascript(string webFormUrl,string features
)
{
string js=@"<スクリプト言語=javascript>
showModalDialog('"+webFormUrl+"','','"+features+"');</script>";
jsを返します。
}
/// <概要>
/// 関数名:ShowModalDialogWindow
/// 関数の説明: モーダルウィンドウを開く
/// </概要>
/// <param name="webFormUrl"></param>
/// <戻り値></戻り値>
public static void ShowModalDialogWindow(string webFormUrl)
{
文字列 js=ShowModalDialogJavascript(webFormUrl);
HttpContext.Current.Response.Write(js);
public static void ShowModalDialogWindow(string webFormUrl,string features
)
{
string js=ShowModalDialogJavascript(webFormUrl,features);
HttpContext.Current.Response.Write(js);
}
public static void ShowModalDialogWindow(string webFormUrl,int width,int height,int top,int left)
{
文字列機能 = "dialogWidth:"+width.ToString() + "px"
+";dialogHeight:" + height.ToString() + "px"
+";dialogLeft:" + left.ToString() + "px"
+";dialogTop:" +top.ToString() + "px"
+";センター:はい;ヘルプ = いいえ;サイズ変更可能:いいえ;ステータス:いいえ;スクロール = いいえ";
ShowModalDialogWindow(webFormUrl,features);
public
static void SetHtmlElementValue(文字列フォーム名,文字列要素名,文字列要素値)
{
string js=@"<Script language='JavaScript'>if(document."+formName+"." + elementName +"!=null){document."+formName+".value ="+ elementValue +";}</Script>";
HttpContext.Current.Response.Write(js);
}
}
}
http://www.cnblogs.com/fds2003/archive/2006/10/20/534208.html