lhgdialog消息弹出框的js很好用,但是不支持服务器控件,是因为服务器控件点击会刷新页面,所以搞了一个类
首先引入js文件
<script src="Scripts/lhgdialog/lhgcore.lhgdialog.min.js" type="text/javascript"></script>
代码如下:
using System; using System.Collections.Generic; using System.Web; using System.Text; using System.Web.UI; namespace JboxDemo { public class MessageBox : System.Web.UI.Page { /// <summary> /// 弹出消息框(没有最大化和最小化) /// </summary> /// <param name="page">一般为this.page</param> /// <param name="title">弹出框标题</param> /// <param name="context">弹出框内容</param> public static void showinfo(Page page,string title,string context) { StringBuilder msg = new StringBuilder(); msg.Append("<script type=\"text/javascript\">"); msg.Append(" $(function () {$.dialog({lock: true,title: '"+title+"',content: '"+context+"',max:false,min:false,fixed: true,});});"); msg.Append("</script>"); page.ClientScript.RegisterStartupScript(page.GetType(),"msg",msg.ToString()); } /// <summary> /// 创建一个右下角浮动的消息窗口 /// </summary> /// <param name="page">一般为this.page</param> /// <param name="title">标题</param> /// <param name="context">内容</param> /// <param name="width">弹出框的宽度</param> /// <param name="height">弹出框的高度</param> public static void showSmallinfo(Page page, string title, string context, string width,string height) { StringBuilder msg = new StringBuilder(); msg.Append("<script type=\"text/javascript\">"); msg.Append(" $(function () {$.dialog({id: 'msg',title: '" + title + "',content: '" + context + "'," + width + ",height:" + height + ",left: '100%',top: '100%',fixed: true,drag: false,resize: false});});"); msg.Append("</script>"); page.ClientScript.RegisterStartupScript(page.GetType(), "msg", msg.ToString()); } /// <summary> /// 弹出一个指定大小的层 /// </summary> /// <param name="page">一般为this.page</param> /// <param name="title">标题</param> /// <param name="context">内容(可以为url:www.baidu.com)</param> /// <param name="width">弹出框的宽度</param> /// <param name="height">弹出框的高度</param> public static void shownewbox(Page page, string title, string context, string width, string height) { StringBuilder msg = new StringBuilder(); msg.Append("<script type=\"text/javascript\">"); msg.Append(" $(function () {$.dialog({title: '" + title + "',content: '" + context + "'," + width + ",height:" + height + ",fixed: true});});"); msg.Append("</script>"); page.ClientScript.RegisterStartupScript(page.GetType(), "msg", msg.ToString()); } } }
这样可以直接调用了