修改Ben的PopupBox
来源:互联网 发布:双重网络怎么解决 编辑:程序博客网 时间:2024/04/28 22:41
最近因为工作需要我研究了下类似MSN的消息提示框方面的程序,发现BEN的PopupBox还不错
但在asp.net 2.0下运行时弹出的消息框是却是一片白色...没任何内容,
因为没源代码,所以我只好用reflector获取了源代码
并修改了代码里的小BUG,以适应asp.net 2.0
关键代码我贴出来,有需要研究的朋友可去看看,并可点击下载修改后的源码,内附简单调用方法 (下载地址)
using System;using System.ComponentModel;using System.Drawing;using System.Drawing.Imaging;using System.IO;using System.Reflection;using System.Web;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;namespace benSoft.web.WebControls.PopupBox{ [Designer(typeof(PopupBoxDesigner)), PersistChildren(false), ToolboxData("<{0}:PopupBox runat=server></{0}:PopupBox>"), DefaultProperty("Text"), ParseChildren(false)] public class PopupBox : Panel { private bool _Focus = false; private Unit _height = Unit.Pixel(120); private string _sound; private string _text = ""; private int _timer = 3; private Unit _width = Unit.Pixel(200); private string ScriptKey = "benSoft.web.WebControls.PopupBox"; private string ScriptParams = "/r/n/t/t<script language=javascript>/r/n/t/t/t/**//t/t /r/n/t/t/tvar tmpHtmlTemplate;/r/n/t/t/tvar w = parseInt('{1}');/t//box's width/r/n/t/t/tvar h = parseInt('{2}');/t//box's height/r/n/t/t/tvar sound = /"{3}/";/r/n/t/t/tvar wFocus = {4};/r/n/t/t/tvar dtime = {5};/r/n /t /r/n/t/t/ttmpHtmlTemplate = document.getElementById(/"{0}tmpHtmlTemplate/"); /r/n/t/t</script>/r/n/t/t";public void CreatePopup() { Label label; HtmlInputHidden hiddens; Assembly executingAssembly = Assembly.GetExecutingAssembly(); string str = ""; string str2 = this.Context.Request.Url.ToString(); str2 = str2 + ((str2.IndexOf("?") >= 0) ? "&" : "?") + this.UniqueMark; Stream manifestResourceStream = executingAssembly.GetManifestResourceStream("benSoft.web.WebControls.PopupBox.dialog.htm"); manifestResourceStream.Position = 0L; str = new StreamReader(manifestResourceStream).ReadToEnd().Replace("[bgimagepath]", str2 + "bgImage=true").Replace("[imagepath]", str2 + "Image=true"); Panel panel = new Panel(); panel.Attributes["Style"] = string.Format("font-size:{0};color:{1};font-family:{2}", this.Font.Size, this.ForeColor, this.Font.Name); panel.Controls.Add(new LiteralControl(this.Text)); if (this.HorizontalAlign != HorizontalAlign.NotSet) { panel.Attributes["align"] = this.HorizontalAlign.ToString(); } else { panel.Attributes["align"] = "center"; } StringWriter writer = new StringWriter(); HtmlTextWriter writer2 = new HtmlTextWriter(writer); panel.RenderControl(writer2); if (base.FindControl(this.preMark + this.UniqueMark + "tmpLabel") == null) { label = new Label(); } else { label = (Label)base.FindControl(this.preMark + this.UniqueMark + "tmpLabel"); } label.ID = this.preMark + this.UniqueMark + "tmpLabel"; label.Attributes["Style"] = "display:none"; label.Text = writer.ToString(); base.Controls.Add(label); str = str.Replace("[MessageParam]", this.preMark + this.UniqueMark + "tmpLabel"); if (base.FindControl(this.preMark + this.UniqueMark + "tmpHtmlTemplate") == null) { hiddens = new HtmlInputHidden(); } else { hiddens = (HtmlInputHidden)base.FindControl(this.preMark + this.UniqueMark + "tmpHtmlTemplate"); } hiddens.ID = this.preMark + this.UniqueMark + "tmpHtmlTemplate"; hiddens.Value = HttpUtility.UrlEncode(str).Replace("+", "%20"); base.Controls.Add(hiddens); Stream stream = executingAssembly.GetManifestResourceStream("benSoft.web.WebControls.PopupBox.script.htm"); stream.Position = 0L; string script = new StreamReader(stream).ReadToEnd(); base.Page.ClientScript.RegisterStartupScript(this.GetType(),this.ScriptKey + "ScriptParams", string.Format(this.ScriptParams, new object[] { this.preMark + this.UniqueMark, this.Width, this.Height, this.Sound, this.Focus.ToString().ToLower(), this.Timer })); base.Page.ClientScript.RegisterStartupScript(this.GetType(),this.ScriptKey + "Scripts", script); base.Page.ClientScript.RegisterStartupScript(this.GetType(),this.ScriptKey + "Popup", "<script language=javascript>Popup();</script>"); }protected override void OnLoad(EventArgs e) { Assembly executingAssembly = Assembly.GetExecutingAssembly(); if ((this.Context.Request[this.UniqueMark + "Image"] != null) || (this.Context.Request["$Ben$DesignImage"] != null)) { Bitmap bitmap = new Bitmap(executingAssembly.GetManifestResourceStream("benSoft.web.WebControls.PopupBox.branding_Full2.gif")); this.Context.Response.Clear(); bitmap.Save(this.Context.Response.OutputStream, ImageFormat.Gif); bitmap.Dispose(); this.Context.Response.End(); } else if ((this.Context.Request[this.UniqueMark + "bgImage"] != null) || (this.Context.Request["$Ben$DesignbgImage"] != null)) { Bitmap bitmap2 = new Bitmap(executingAssembly.GetManifestResourceStream("benSoft.web.WebControls.PopupBox.headerGRADIENT_Tall.gif")); this.Context.Response.Clear(); bitmap2.Save(this.Context.Response.OutputStream, ImageFormat.Gif); bitmap2.Dispose(); this.Context.Response.End(); } }[DefaultValue(false), Category("Popup Box"), Bindable(true), Description("PopupBox 弹出时, 窗口是否获取焦点")] public new bool Focus { get { return this._Focus; } set { this._Focus = value; } }[Description("Popup Box's Height")] public override Unit Height { get { return this._height; } set { this._height = value; } }[Browsable(false), Bindable(false), Category("Popup Box"), ReadOnly(true)] public string PageName { get { string absolutePath = this.Context.Request.Url.AbsolutePath; return absolutePath.Substring(absolutePath.LastIndexOf("/") + 1, (absolutePath.Length - absolutePath.LastIndexOf("/")) - 1); } }private string preMark { get { string clientID = base.NamingContainer.ClientID; clientID = (clientID == null) ? "" : clientID; return (clientID + ((clientID == "") ? "" : "_")); } }[Description("Popup 声音文件路径"), Category("Popup Box"), DefaultValue(""), Bindable(true)] public string Sound { get { return this._sound; } set { this._sound = value; } }[Description("Popup Box 的文本"), Bindable(true), Category("Popup Box"), DefaultValue("")] public string Text { get { return this._text; } set { this._text = value; } }[Description("PopupBox 消失定时器, 单位为秒"), DefaultValue(3), Bindable(true), Category("Popup Box")] public int Timer { get { return this._timer; } set { this._timer = value; } }public string UniqueMark { get { return base.ClientID; } }public override bool Visible { get { return true; } }[Description("Popup Box's Width")] public override Unit Width { get { return this._width; } set { this._width = value; } } }}
- 修改Ben的PopupBox
- 打造自己的benSoft.PopupBox
- 程序员阿BEN的SOHO生活
- 程序员阿BEN的SOHO生活
- 程序员阿BEN的SOHO生活(转载)
- 程序员阿BEN的SOHO生活
- 程序员阿BEN的SOHO生活
- Professor Ben 唯一分解定理:因子的因子个数
- 在winXP在tomcat下配置运行jsp、servlet和ben的环境
- 恢复被"Trojan-Downloader.Win32.Agent.ben"感染的exe文件
- 关于直接操纵界面设计(引自:《用户界面设计-有效的人机交互策略》,Ben Shneiderman Catherine Plaisant》)
- Ben Forta:网络浏览器和Flash的分界线在变化 (1)
- (转)Andreessen Horowitz联合创始人Ben Horowitz的创业谈:创业中的挣扎
- 个人如何采用敏捷的工作方法[作者 Ben Linders ,译者 李彬 ]
- 项目总结(by BEN)
- POJ 3604 Professor Ben
- POJ 3604 Professor Ben
- Friends--S01E23--Ben出生
- 第一博
- 同步、异步、阻塞和非阻塞的概念
- Javascript 事件集锦
- Number triangle(PKU1163)
- Common Subsequence(PKU 1458)
- 修改Ben的PopupBox
- The 3n + 1 problem(PKU 1207)
- 六一儿童节重量级新闻,新百米纪录诞生
- I Think I Need a Houseboat(PKU1005)
- RMI实例入门
- 【经典推荐】每个初学者都应该搞懂的问题 (转)
- [struts]文件上传
- 日常起居六忌是什么?
- 文件列表命令