WebControl示例

None.gif using  System;
None.gif
using  System.Web.UI;
None.gif
using  System.Text;
None.gif
None.gif
namespace  Goodspeed.Web
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Summary description for WebTimer
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class WebTimer:Control, IPostBackEventHandler
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif        
- Properties -#region - Properties -
InBlock.gif        
private int _interval = 5000;
InBlock.gif        
public int Interval
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn _interval; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ _interval = value; }
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private bool _enabled;
InBlock.gif
InBlock.gif        
public bool Enabled
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn _enabled; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ _enabled = value; }
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private static readonly object EventTimer = new object();
InBlock.gif
InBlock.gif        
public bool Visible
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn base.Visible; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gifbase.Visible = value; }
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
- Constructor -#region - Constructor -
InBlock.gif        
public WebTimer()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// TODO: Add constructor logic here
InBlock.gif            
//
ExpandedSubBlockEnd.gif
        }
 
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
- Event -#region - Event -
InBlock.gif        
public event EventHandler Timer
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            add 
dot.gif{ Events.AddHandler(EventTimer, value); }
ExpandedSubBlockStart.gifContractedSubBlock.gif            remove 
dot.gif{ Events.RemoveHandler(EventTimer, value); }
ExpandedSubBlockEnd.gif        }
 
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// event handler functions
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="e"></param>

InBlock.gif        protected virtual void OnTime(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            EventHandler TimerHandler 
= (EventHandler)Events[EventTimer];
InBlock.gif
InBlock.gif            
if (TimerHandler != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                TimerHandler(
this, e);
ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
- IPostBackEventHandler -#region - IPostBackEventHandler -
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 实现IPostBackEventHandler接口
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="eventArgs"></param>

InBlock.gif        void IPostBackEventHandler.RaisePostBackEvent(string eventArgs)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            OnTime(EventArgs.Empty);
ExpandedSubBlockEnd.gif        }
 
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
private string BulidJavascript()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            StringBuilder sb 
= new StringBuilder();
InBlock.gif            sb.Append(
"<script>");
ExpandedSubBlockStart.gifContractedSubBlock.gif            sb.AppendFormat(
"setTimeout(\"dot.gif{0}\",{1})"new object[] dot.gifthis.Page.GetPostBackEventReference(this), _interval.ToString() });
InBlock.gif            sb.Append(
"</script>");
InBlock.gif            
return sb.ToString();
ExpandedSubBlockEnd.gif        }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
- Override -#region - Override -
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="e"></param>
InBlock.gif        
/// <remarks>
InBlock.gif        
/// 此时调用page函数
ExpandedSubBlockEnd.gif        
/// </remarks>

InBlock.gif        protected override void OnPreRender(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
base.OnPreRender(e);
InBlock.gif            
//获取对客户端脚本函数的引用,调用该函数将使服务器发送回该页。
InBlock.gif            
//该方法还将一个参数传递到在服务器上执行回发处理的服务器控件。
InBlock.gif
            Page.GetPostBackEventReference(this"");
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="writer"></param>
InBlock.gif        
/// <remarks>
InBlock.gif        
/// page已进入绘制状态,此时调用page对象的任何函数都太迟了
ExpandedSubBlockEnd.gif        
/// </remarks>

InBlock.gif        protected override void Render(HtmlTextWriter writer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (Page != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//确认在运行时为指定的 ASP.NET 服务器控件呈现 HtmlForm 控件
InBlock.gif
                Page.VerifyRenderingInServerForm(this);
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
if (_enabled)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                writer.Write(BulidJavascript());
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }
 
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值