热门标签 | 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



推荐阅读
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社区 版权所有