CustomMessage.cs

出自ProgWiki

跳轉到: 導航, 搜尋

用途

程式碼

class CustomMessage
{
	public static string JSStringEscape(string raw, bool inHtmlAttribute)
	{
		string raw2 = raw.Replace("\r\n", "\\n").Replace("\r", "").Replace("\n", "\\n");
		if (inHtmlAttribute)
			raw2 = raw2.Replace("\"", """).Replace("'", "\\'");
		else
			raw2 = raw2.Replace("'", "\\'").Replace("\"", "\\\"");
		return raw2;
	}
 
 
	public static void Alert(Page thisPage, string strAlertMessage)
	{
		string strJS = string.Format(
@"<script type='text/javascript'>
/*<![CDATA[*/
alert('{0}');
/*]]>*/
</script>",
				JSStringEscape(strAlertMessage, false));
 
		string strKey = "CustomMessage_Alert";
 
		if (thisPage.FindControl("ToolkitScriptManager1") == null)
		{
			thisPage.ClientScript.RegisterStartupScript(
				typeof(string),
				strKey,
				strJS,
				false);
		}
		else
		{
			AjaxControlToolkit.ToolkitScriptManager.RegisterClientScriptBlock(
				thisPage,
				typeof(string),
				strKey,
				strJS,
				false);
		}
	}
 
	public static void AlertAndRedirect(Page thisPage, int AlertNum, string strUrl)
	{
		string strJS = string.Format(
@"<script type='text/javascript'>
/*<![CDATA[*/
alert('{0}');
location.href='{1}';
/*]]>*/
</script>",
				JSStringEscape(strAlertMessage, false),
				strUrl);
 
		string strKey = "CustomMessage_AlertAndRedirect";
 
		if (thisPage.FindControl("ToolkitScriptManager1") == null)
		{
			thisPage.ClientScript.RegisterStartupScript(
				typeof(string),
				strKey,
				strJS,
				false);
		}
		else
		{
			AjaxControlToolkit.ToolkitScriptManager.RegisterClientScriptBlock(
				thisPage,
				typeof(string),
				strKey,
				strJS,
				false);
		}
	}
}
個人工具
名字空間
變換
動作
導航
分類
其他
技術類News或部落格
工具箱