asp.net弹出alert提示框

代码
///<summary>
/// 信息输出通用方法
///</summary>
publicclass MessageObject
{
///<summary>
/// 一般输出
///</summary>
///<param name="str"></param>
publicstaticvoid Write(string str)
{
System.Web.HttpContext.Current.Response.Write(str);
}
///<summary>
/// 显示一段自定义的输出代码
///</summary>
///<param name="MyPage"></param>
///<param name="strCode"></param>
publicstaticvoid ShowJS(System.Web.UI.Page MyPage, string strCode)
{
StringBuilder sb
=new StringBuilder();
sb.Append(
"<script language=\"javascript\"> ");
sb.Append(strCode.Trim());
sb.Append(
"</script>");
MyPage.Response.Write(sb.ToString());
}
///<summary>
/// 页面重载
///</summary>
publicstaticvoid Location()
{
StringBuilder sb
=new StringBuilder();
sb.Append(
"<script language=\"javascript\"> ");
sb.Append(
"window.location.href=window.location.href;");
sb.Append(
"</script>");
System.Web.HttpContext.Current.Response.Write(sb.ToString());
}
///<summary>
/// 显示一个弹出窗口
///</summary>
///<param name="str"></param>
publicstaticvoid Show(string str)
{
StringBuilder sb
=new StringBuilder();
sb.Append(
"<script language=\"javascript\"> ");
sb.Append(
"alert(\"" + str.Trim() + "\"); ");
sb.Append(
"</script>");
System.Web.HttpContext.Current.Response.Write(sb.ToString());
}
///<summary>
/// 显示一个弹出窗口,并关闭当前页
///</summary>
///<param name="str"></param>
publicstaticvoid ShowClose(string str)
{
System.Text.StringBuilder sb
=new System.Text.StringBuilder();
sb.Append(
"<script language=\"javascript\"> ");
sb.Append(
"alert(\"" + str.Trim() + "\"); ");
sb.Append(
"window.close(); ");
sb.Append(
"</script> ");
System.Web.HttpContext.Current.Response.Write(sb.ToString());
}
///<summary>
/// 显示一个弹出窗口,并转向当前页(刷新)
///</summary>
///<param name="str"></param>
publicstaticvoid ShowLocation(string str)
{
StringBuilder sb
=new StringBuilder();
sb.Append(
"<script language=\"javascript\"> ");
sb.Append(
"alert(\"" + str.Trim() + "\"); ");
sb.Append(
"window.location.href=window.location.href; ");
sb.Append(
"</script>");
System.Web.HttpContext.Current.Response.Write(sb.ToString());
}
///<summary>
/// 显示一个弹出窗口,并转向目标页(导航)
///</summary>
///<param name="str"></param>
///<param name="url"></param>
publicstaticvoid ShowRedirect(string str, string url)
{
StringBuilder sb
=new StringBuilder();
sb.Append(
"<script language=\"javascript\"> ");
sb.Append(
"alert(\"" + str.Trim() + "\"); ");
sb.Append(
"window.location.href=\"" + url.Trim() + "\"; ");
sb.Append(
"</script>");
System.Web.HttpContext.Current.Response.Write(sb.ToString());
}
///<summary>
/// 显示一个弹出窗口,并转向上一页
///</summary>
///<param name="str"></param>
publicstaticvoid ShowPre(string str)
{
StringBuilder sb
=new StringBuilder();
sb.Append(
"<script language=\"javascript\"> ");
sb.Append(
"alert(\"" + str.Trim() + "\"); ");
sb.Append(
"var p=document.referrer; ");
sb.Append(
"window.location.href=p; ");
sb.Append(
"</script>");
System.Web.HttpContext.Current.Response.Write(sb.ToString());
}
///<summary>
/// 重定向
///</summary>
///<param name="url"></param>
publicstaticvoid RedirectPage(string url)
{
string path ="http://"+ System.Web.HttpContext.Current.Request.Url.Host + url;
StringBuilder sb
=new StringBuilder();
sb.Append(
"<script language=\"javascript\"> ");
sb.Append(
string.Format("window.location.href='{0}';", @path));
sb.Append(
"</script>");
System.Web.HttpContext.Current.Response.Write(sb.ToString());
}
}

 

posted @ 2010-11-05 14:19  云翔紫梦  阅读(800)  评论(0编辑  收藏  举报