模拟Confirm的Web自定义控件

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Collections;
using System.Collections.Specialized;
 
namespace PublicControls
{
     ///<summary>
     /// MsgBoxControl 的摘要说明。
     ///</summary>
 
     public class MsgBoxControl : Control,IPostBackDataHandler,IPostBackEventHandler
     {
         #region 预定义
    
         #endregion
 
         #region 属性
        
         #endregion
 
         #region 事件/方法
 
         ///<summary>
         /// 获取回发的数据
         ///</summary>
         ///<param name="postDataKey"></param>
         ///<param name="values"></param>
         ///<returns></returns>
         public bool LoadPostData(String postDataKey, NameValueCollection values)
         {
 
            return false;       
         }
 
         ///<summary>
         /// 数据回发事件
         ///</summary>
         public void RaisePostDataChangedEvent()
         {
 
         }
 
         ///<summary>
         /// 回送事件
         ///</summary>
         ///<param name="e"></param>
         public void RaisePostBackEvent(string e)
         {
 
         }
 
         ///<summary>
         /// 输出预处理
         ///</summary>
         ///<param name="e"></param>
         protected override void OnPreRender(EventArgs e)
         {
             
         }
        
         ///<summary>
         /// 添加控件方法,该方法为指定控件添加onclick属性
         ///</summary>
         ///<param name="button">LinkButton 控件对象 </param>
         ///<param name="msg"> 提示信息 </param>
         public void AddAttributes(System.Web.UI.WebControls.LinkButton button,string msg)
         {
              button.Attributes.Add("onclick","return onformsubmit(this,'"+msg+"')");
         }
 
         ///<summary>
         /// 添加控件方法,该方法为指定控件添加onclick属性
         ///</summary>
         ///<param name="button">Button 控件对象 </param>
         ///<param name="msg"> 提示信息 </param>
         public void AddAttributes(System.Web.UI.WebControls.Button button,string msg)
         {
              button.Attributes.Add("onclick","return onformsubmit(this,'"+msg+"')");
         }
 
         #endregion
 
         #region 输出
         ///<summary>
         /// 将此控件呈现给指定的输出参数。
         ///</summary>
         ///<param name="output"> 要写出到的 HTML 编写器 </param>
         protected override void Render(HtmlTextWriter output)
         {
              string View=ViewString();
 
              output.Write(View);
         }
         #endregion
 
         #region 其他函数
         ///<summary>
         /// 输出字符串
         ///</summary>
         ///<returns></returns>
         string ViewString()
         {
              string view="";
              view+="<script language=/"javascript/">/n";
              view+="<!--/n";
              view+="var EventObj;";
              view+="function operation(obj)/n";
              view+="{/n";
              view+="if(obj.innerHTML==/"0/")/n";
              view+="{/n";
              view+="obj.innerHTML=/"2/";/n";
              view+="obj.parentNode.parentNode.style.height=/"0px/";/n";  
              view+="obj.parentNode.nextSibling.style.display=/"none/";/n";
              view+="obj.parentNode.nextSibling.nextSibling.nextSibling.style.display=/"none/";/n";
              view+="}";
              view+="else if(obj.innerHTML==/"2/")/n";
              view+="{";
              view+="obj.innerHTML=/"0/";/n";
              view+="obj.parentNode.nextSibling.style.display=/"block/";/n";
              view+="obj.parentNode.nextSibling.nextSibling.nextSibling.style.display=/"block/";/n";
              view+="}/n";
              view+="else/n";
              view+="{/n";
              view+="obj.parentNode.parentNode.style.display='none';/n";  
              view+="}/n";
              view+="}/n";
              view+="function onformsubmit(obj,msg)/n";
              view+="{/n";
              view+="EventObj = obj;/n";
              view+="win.style.left=document.body.clientWidth/2-100;/n";
              view+="win.style.top=document.body.clientHeight/2-150;/n";
              view+="win.style.display=/"block/";/n";
              view+="win.childNodes[1].innerHTML=msg;/n";
              view+="return false;/n";
              view+="}/n";
              view+="function formsubmit()/n";
              view+="{/n";
              view+="eventTarget = EventObj.id.split(/"_/").join(/"$/").split(/"$$/").join(/"$_/");/n";
              view+="eventArgument = '';/n";
              view+="__doPostBack(eventTarget, eventArgument);/n";
              view+="}/n";
              view+="//-->/n";
              view+="</script>/n";
 
 
              view+="<div id=/"win/" style=/"position:absolute;z-index=999; background-color: #FFFFFF;BORDER-RIGHT:navy thin solid; BORDER-TOP:navy thin solid; DISPLAY:none; BORDER-LEFT:navy thin solid; WIDTH:200px; BORDER-BOTTOM:navy thin solid;/">/n";
              view+="<span style=/"FONT-SIZE: 9pt;WIDTH: 100%;COLOR: white;BACKGROUND-COLOR: navy;">/n";
              view+="<font style=/"CURSOR: hand/" onclick=/"operation(this);/">0</font> <font style=/"CURSOR: hand/" onclick=/"operation(this);/">/n";
              view+="r</font></span><span><!-- 提示信息--></span><br>/n";
              view+="<span style=/"/"><font style=/"CURSOR: hand/" onclick=/"formsubmit();/">[ 确定]</font>&nbsp;&nbsp;&nbsp;<font style=/"CURSOR: hand/" onclick=/"operation(this);/">[取消]</font>/n";
              view+="</span>/n";
              view+="</div>/n";
              return view;
         }
         #endregion
     }
}
 

你可能感兴趣的:(confirm)