ConfirmDialog

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

1. 界面:

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


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

2. 界面的后台代码:

None.gif namespace  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 
= args.Title;
InBlock.gif            lbText.Text 
= args.Text;
InBlock.gif            btnYes.Command 
+= args.YesCmdHandler;
InBlock.gif            btnNo.Command 
+= args.NoCmdHandler;
InBlock.gif            btnYes.CommandArgument 
= args.YesCmdArgs;
InBlock.gif            btnNo.CommandArgument 
= args.NoCmdArgs;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif


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

3. ConfirmDialogArgs类

None.gif using  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    
/**//// <summary>
InBlock.gif    
/// ConfirmDialgArgs 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

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        
/**//// <summary> 
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// </summary> 

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 
= 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        
/**//// <summary> 
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// </summary> 

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 
= 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        
/**//// <summary> 
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// </summary> 

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 
= 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        
/**//// <summary> 
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// </summary> 

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 
= 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        
/**//// <summary> 
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// </summary> 

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 
= 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        
/**//// <summary> 
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// </summary> 

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 
= 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.gif private   void  Page_Load( object  sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            ConfirmDialog dialog 
= FindControl("confirmDialog"as ConfirmDialog;
InBlock.gif            ConfirmDialogArgs args 
= MyController.State["ConfirmDialogArgs"as ConfirmDialogArgs;
InBlock.gif            dialog.InitDialog(args);
ExpandedBlockEnd.gif        }

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

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

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


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

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

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


现在这个对话框一切正常,都还好用.我这里只是提供一个建议,不喜勿怪.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值