科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道应用软件模拟Confirm的Web自定义控件

模拟Confirm的Web自定义控件

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

按项目要求做的,为了方便,做成自定义控件了

作者:待缘 来源:CSDN 2008年3月29日

关键字: 控件 web 模拟 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
     }
    • 评论
    • 分享微博
    • 分享邮件
    邮件订阅

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章