热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ConfirmDialog

为了使用CNBLOG上的服务器端ConfirmDialog,我自己做了一个,用起来还不错.1.界面:

为了使用CNBLOG上的服务器端ConfirmDialog,我自己做了一个,用起来还不错.

1. 界面:

ExpandedBlockStart.gifContractedBlock.gif<%dot.gif&#64; Control Language&#61;"c#" AutoEventWireup&#61;"false" Codebehind&#61;"ConfirmDialog.ascx.cs" Inherits&#61;"Newtop.Common.Web.UserControls.ConfirmDialog" TargetSchema&#61;"http://schemas.microsoft.com/intellisense/ie5" %>
None.gif
<div id&#61;"Header" class&#61;"Dialog">
None.gif    
<div id&#61;"Header_Header" class&#61;"DialogTitle">
None.gif        
<span>
None.gif            
<asp:Label id&#61;"lbTitle" runat&#61;"server">Labelasp:Label>
None.gif        
span>
None.gif    
div>
None.gif    
<div id&#61;"Header_Contents" class&#61;"DialogBody">
None.gif        
<span id&#61;"Header_lblOutput">
None.gif            
<asp:Label Runat&#61;"server" id&#61;"lbText">Dialog Textasp:Label>span>
None.gif        
<div style&#61;"MARGIN-TOP: 12px">
None.gif            
<asp:LinkButton Runat&#61;"server" CssClass&#61;"Button" id&#61;"btnYes" CommandName&#61;"Yes">Yesasp:LinkButton>
None.gif            
<asp:LinkButton Runat&#61;"server" CssClass&#61;"Button" id&#61;"btnNo" CommandName&#61;"No">Noasp:LinkButton>
None.gif            
<BR>
None.gif        
div>
None.gif    
div>
None.gif
div>


界面可以自己定义,但是必须要有两个Label和两个Button,而且名字必须跟上面的一样.

2. 界面的后台代码:

None.gifnamespace Newtop.Common.Web.UserControls
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
using System.Web.UI.WebControls;
InBlock.gif
InBlock.gif    
public class ConfirmDialog : System.Web.UI.UserControl
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
protected System.Web.UI.WebControls.Label lbTitle;
InBlock.gif        
protected System.Web.UI.WebControls.LinkButton btnYes;
InBlock.gif        
protected System.Web.UI.WebControls.LinkButton btnNo;
InBlock.gif        
protected System.Web.UI.WebControls.Label lbText;
InBlock.gif
InBlock.gif        
public void InitDialog(ConfirmDialogArgs args)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            lbTitle.Text 
&#61; args.Title;
InBlock.gif            lbText.Text 
&#61; args.Text;
InBlock.gif            btnYes.Command 
&#43;&#61; args.YesCmdHandler;
InBlock.gif            btnNo.Command 
&#43;&#61; args.NoCmdHandler;
InBlock.gif            btnYes.CommandArgument 
&#61; args.YesCmdArgs;
InBlock.gif            btnNo.CommandArgument 
&#61; args.NoCmdArgs;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif


类中关键是InitDialog方法,他接收一个ConfirmDialogArgs的实例作为参数,用来初始化Dialog.

3. ConfirmDialogArgs类

None.gifusing System;
None.gif
using System.Web.UI.WebControls;
None.gif
None.gif
namespace Newtop.Common.Web.UserControls
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// 
InBlock.gif    
/// ConfirmDialgArgs 的摘要说明。
ExpandedSubBlockEnd.gif    
/// 

InBlock.gif    public class ConfirmDialogArgs
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
public ConfirmDialogArgs()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockEnd.gif        }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
Title 属性#region  Title 属性
InBlock.gif
InBlock.gif        
private string title;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////  
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// 
 

InBlock.gif        public string Title
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return title;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                title 
&#61; value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
Text 属性#region  Text 属性
InBlock.gif
InBlock.gif        
private string text;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////  
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// 
 

InBlock.gif        public string Text
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return text;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                text 
&#61; value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
YesCmdHandler 属性#region  YesCmdHandler 属性
InBlock.gif
InBlock.gif        
private CommandEventHandler yesCmdHandler;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////  
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// 
 

InBlock.gif        public CommandEventHandler YesCmdHandler
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return yesCmdHandler;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                yesCmdHandler 
&#61; value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
NoCmdHandler 属性#region  NoCmdHandler 属性
InBlock.gif
InBlock.gif        
private CommandEventHandler noCmdHandler;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////  
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// 
 

InBlock.gif        public CommandEventHandler NoCmdHandler
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return noCmdHandler;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                noCmdHandler 
&#61; value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
YesCmdArgs 属性#region  YesCmdArgs 属性
InBlock.gif
InBlock.gif        
private string yesCmdArgs;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////  
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// 
 

InBlock.gif        public string YesCmdArgs
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return yesCmdArgs;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                yesCmdArgs 
&#61; value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
NoCmdArgs 属性#region  NoCmdArgs 属性
InBlock.gif
InBlock.gif        
private string noCmdArgs;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**////  
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// 
 

InBlock.gif        public string NoCmdArgs
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return noCmdArgs;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                noCmdArgs 
&#61; value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}


这个类比较简单,请对照InitDialog方法理解,这里就不在赘述了.

4. 使用方法
其实使用这个东西很简单,分以下几步:

4.1 建立页面.
把 1 中的用户控件放在一个aspx页面中.

4.2 在aspx文件中为对话框初始化一个ConfirmDialogArgs的实例.
None.gifprivate void Page_Load(object sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            ConfirmDialog dialog 
&#61; FindControl("confirmDialog"as ConfirmDialog;
InBlock.gif            ConfirmDialogArgs args 
&#61; MyController.State["ConfirmDialogArgs"as ConfirmDialogArgs;
InBlock.gif            dialog.InitDialog(args);
ExpandedBlockEnd.gif        }

因为我的程序中用了UIP,所以,我这里是直接从State中取出了一个ConfirmDialogArgs的实例.

下面我们来看一个初始化ConfirmDialogArgs的例子:

None.gif        ConfirmDialogArgs args &#61; new ConfirmDialogArgs();
None.gif        args.Title 
&#61; "Delete";
None.gif        args.Text 
&#61; "Delete it!";
None.gif        args.YesCmdHandler 
&#61; new CommandEventHandler(this.DeleteVfSystemCommand);
None.gif        args.YesCmdArgs 
&#61; e.CommandArgument.ToString();
None.gif
None.gif
None.gif        MyController.State[
"ConfirmDialogArgs"&#61; args;
None.gif
None.gif        MyController.PerformConfirm();


最后那一句是转向显示对话框的页面.

上面代码中有一个DeleteVfSystemCommand的方法,用来作为对话框选择了"是"的时候做委托.下面是他的具体代码:

None.gifprivate void DeleteVfSystemCommand(object sender,CommandEventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            IVfSystemDAO dao 
&#61; Factory.VfSystemDAO;
InBlock.gif            dao.DeleteVfSystem(Convert.ToInt32(e.CommandArgument));
InBlock.gif            MyController.PerformVfSystemManage();
ExpandedBlockEnd.gif        }


现在这个对话框一切正常,都还好用.我这里只是提供一个建议,不喜勿怪.

转:https://www.cnblogs.com/na57/archive/2005/04/11/135758.html



推荐阅读
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • 本文由编程笔记#小编为大家整理,主要介绍了logistic回归(线性和非线性)相关的知识,包括线性logistic回归的代码和数据集的分布情况。希望对你有一定的参考价值。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 本文介绍了Redis的基础数据结构string的应用场景,并以面试的形式进行问答讲解,帮助读者更好地理解和应用Redis。同时,描述了一位面试者的心理状态和面试官的行为。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 本文详细介绍了Spring的JdbcTemplate的使用方法,包括执行存储过程、存储函数的call()方法,执行任何SQL语句的execute()方法,单个更新和批量更新的update()和batchUpdate()方法,以及单查和列表查询的query()和queryForXXX()方法。提供了经过测试的API供使用。 ... [详细]
  • 利用Visual Basic开发SAP接口程序初探的方法与原理
    本文介绍了利用Visual Basic开发SAP接口程序的方法与原理,以及SAP R/3系统的特点和二次开发平台ABAP的使用。通过程序接口自动读取SAP R/3的数据表或视图,在外部进行处理和利用水晶报表等工具生成符合中国人习惯的报表样式。具体介绍了RFC调用的原理和模型,并强调本文主要不讨论SAP R/3函数的开发,而是针对使用SAP的公司的非ABAP开发人员提供了初步的接口程序开发指导。 ... [详细]
  • ASP.NET2.0数据教程之十四:使用FormView的模板
    本文介绍了在ASP.NET 2.0中使用FormView控件来实现自定义的显示外观,与GridView和DetailsView不同,FormView使用模板来呈现,可以实现不规则的外观呈现。同时还介绍了TemplateField的用法和FormView与DetailsView的区别。 ... [详细]
  • 本文详细介绍了如何使用MySQL来显示SQL语句的执行时间,并通过MySQL Query Profiler获取CPU和内存使用量以及系统锁和表锁的时间。同时介绍了效能分析的三种方法:瓶颈分析、工作负载分析和基于比率的分析。 ... [详细]
  • This article discusses the efficiency of using char str[] and char *str and whether there is any reason to prefer one over the other. It explains the difference between the two and provides an example to illustrate their usage. ... [详细]
author-avatar
翔英建辉千慧
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有