欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Asp.net 弹出对话框基类(输出alet警告框)

程序员文章站 2023-10-27 11:54:28
using system; using system.data; using system.configuration; using system.web; using s...
using system;
using system.data;
using system.configuration;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.web.ui.htmlcontrols;
using system.text;
namespace ec
{
/// <summary>
/// 信息输出通用方法
/// </summary>
public class messageobject
{
/// <summary>
/// 一般输出
/// </summary>
/// <param name="str"></param>
public static void write(string str)
{
system.web.httpcontext.current.response.write(str);
}
/// <summary>
/// 显示一段自定义的输出代码
/// </summary>
/// <param name="mypage"></param>
/// <param name="strcode"></param>
public static void showjs(system.web.ui.page mypage, string strcode)
{
stringbuilder sb = new stringbuilder();
sb.append("<script language=\"javascript\"> \n");
sb.append(strcode.trim());
sb.append("</script>");
mypage.response.write(sb.tostring());
}
/// <summary>
/// 页面重载
/// </summary>
public static void location()
{
stringbuilder sb = new stringbuilder();
sb.append("<script language=\"javascript\"> \n");
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>
public static void show(string str)
{
stringbuilder sb = new stringbuilder();
sb.append("<script language=\"javascript\"> \n");
sb.append("alert(\"" + str.trim() + "\"); \n");
sb.append("</script>");
system.web.httpcontext.current.response.write(sb.tostring());
}
/// <summary>
/// 显示一个弹出窗口,并关闭当前页
/// </summary>
/// <param name="str"></param>
public static void showclose(string str)
{
system.text.stringbuilder sb = new system.text.stringbuilder();
sb.append("<script language=\"javascript\">\n");
sb.append("alert(\"" + str.trim() + "\"); \n");
sb.append("window.close();\n");
sb.append("</script>\n");
system.web.httpcontext.current.response.write(sb.tostring());
}
/// <summary>
/// 显示一个弹出窗口,并转向当前页(刷新)
/// </summary>
/// <param name="str"></param>
public static void showlocation(string str)
{
stringbuilder sb = new stringbuilder();
sb.append("<script language=\"javascript\"> \n");
sb.append("alert(\"" + str.trim() + "\"); \n");
sb.append("window.location.href=window.location.href;\n");
sb.append("</script>");
system.web.httpcontext.current.response.write(sb.tostring());
}
/// <summary>
/// 显示一个弹出窗口,并转向目标页(导航)
/// </summary>
/// <param name="str"></param>
/// <param name="url"></param>
public static void showredirect(string str, string url)
{
stringbuilder sb = new stringbuilder();
sb.append("<script language=\"javascript\"> \n");
sb.append("alert(\"" + str.trim() + "\"); \n");
sb.append("window.location.href=\"" + url.trim() + "\";\n");
sb.append("</script>");
system.web.httpcontext.current.response.write(sb.tostring());
}
/// <summary>
/// 显示一个弹出窗口,并转向上一页
/// </summary>
/// <param name="str"></param>
public static void showpre(string str)
{
stringbuilder sb = new stringbuilder();
sb.append("<script language=\"javascript\"> \n");
sb.append("alert(\"" + str.trim() + "\"); \n");
sb.append("var p=document.referrer; \n");
sb.append("window.location.href=p;\n");
sb.append("</script>");
system.web.httpcontext.current.response.write(sb.tostring());
}
/// <summary>
/// 重定向
/// </summary>
/// <param name="url"></param>
public static void redirectpage(string url)
{
string path = "http://" + system.web.httpcontext.current.request.url.host + url;
stringbuilder sb = new stringbuilder();
sb.append("<script language=\"javascript\"> \n");
sb.append(string.format("window.location.href='{0}';", @path));
sb.append("</script>");
system.web.httpcontext.current.response.write(sb.tostring());
}
}
}