[控件学习-1]Confirm Button 消息提示button

最近刚好粗略学习完<asp.net服务端控件高程>,后续将会尝试编写适合自己的一些控件.

今天先写了个最简单和实用的消息提示button.可以在执行服务端程序的时候先提醒用户是否确认执行.

代码很简单,如下:

None.gif using  System;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.ComponentModel;
None.gif
None.gif
None.gif[assembly: TagPrefix(
" LangZi.WebControls " " KBT " )]
None.gif
namespace  LangZi.WebControls
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// KBotton 
InBlock.gif    
/// 1.当客户端点击此Button时弹出的提示消息框的内容(Message)
InBlock.gif    
/// 
InBlock.gif    
/// </summary>
InBlock.gif    
/// <remarks>
InBlock.gif    
/// ********************************************************************************
InBlock.gif    
/// 作者: 陈达艺
InBlock.gif    
/// 创始时间:2005-9-8
InBlock.gif    
/// 修改人:
InBlock.gif    
/// 修改时间:
InBlock.gif    
/// 修改内容:
InBlock.gif    
/// 描述:
InBlock.gif    
///    扩充标准Button功能,加入Message确认信息功能
InBlock.gif    
/// *********************************************************************************
ExpandedSubBlockEnd.gif    
/// </remarks>

InBlock.gif
InBlock.gif    [DefaultProperty(
"Text"),
InBlock.gif        ToolboxData(
"<{0}:KButton runat=server></{0}:KButton>")]
InBlock.gif    
public class KButton : System.Web.UI.WebControls.Button, INamingContainer
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
private string _message;
InBlock.gif
InBlock.gif        [Bindable(
true),Category("Appearance"),DefaultValue(""),Description("当客户端点击此Button时弹出的提示消息框的内容")]
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 当客户端点击此Button时弹出的提示消息框的内容
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public string Message
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _message;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _message 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 预呈现,在这里向客户端注册 javascript 块
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="e"></param>

InBlock.gif        protected override void OnPreRender(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
base.OnPreRender(e);
InBlock.gif            
if(_message != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _message.Replace(
"'","\'");
InBlock.gif                
base.Attributes.Add("onclick","return confirm('"+_message+"') ");
ExpandedSubBlockEnd.gif            }

InBlock.gif                
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 将此控件呈现给指定的输出参数。
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="output"> 要写出到的 HTML 编写器 </param>

InBlock.gif        protected override void Render(HtmlTextWriter output)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
base.Render(output);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

使用很简单,如果想提示信息只要在Message属性框输入提示信息,不想放空就可以了.

PS:我还是菜菜,大虾不要笑话------:-)

DownLoad: http://www.cnblogs.com/Files/walkingboy/LangZi.WebControl.KButton.rar

转载于:https://www.cnblogs.com/walkingboy/archive/2005/09/08/232342.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值