zoukankan      html  css  js  c++  java
  • Building ASP.NET Server ControlsCopy of Pager.cs

    // Title: Building ASP.NET Server Controls
    //
    // Chapter: 5 - Event-based Programming
    // File: Pager.cs
    // Written by: Dale Michalk and Rob Cameron
    //
    // Copyright ?2003, Apress L.P.
    using System;
    using System.ComponentModel;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using ControlsBookLib.Ch12.Design;

    namespace ControlsBookLib.Ch05
    {
       [ToolboxData("<{0}:Pager runat=server></{0}:Pager>"),Designer(typeof(CompCntrlDesigner))]
       public class Pager : Control, INamingContainer
       {
          private static readonly object PageCommandKey = new object();
          public event PageCommandEventHandler PageCommand
          {
             add
             {
                Events.AddHandler(PageCommandKey, value);
             }
             remove
             {
                Events.RemoveHandler(PageCommandKey, value);
             }
          }

          protected virtual void OnPageCommand(PageCommandEventArgs pce)
          {
             PageCommandEventHandler pageCommandEventDelegate =
                (PageCommandEventHandler) Events[PageCommandKey];
             if (pageCommandEventDelegate != null)
             {
                pageCommandEventDelegate(this, pce);
             }
          }

          protected override bool OnBubbleEvent(object source, EventArgs e)
          {
             bool result = false;
             CommandEventArgs ce = e as CommandEventArgs;

             if (ce != null)
             {
                if (ce.CommandName.Equals("Page"))
                {
                   PageDirection direction;
                   if (ce.CommandArgument.Equals("Right"))
                      direction = PageDirection.Right;
                   else
                      direction = PageDirection.Left;

                   PageCommandEventArgs pce =
                      new PageCommandEventArgs(direction);

                   OnPageCommand(pce);
                   result = true;
                }
             }
             return result;
          }

          public ButtonDisplay Display
          {
             get
             {
                EnsureChildControls();
                return buttonLeft.Display ;
             }
             set
             {
                EnsureChildControls();
                buttonLeft.Display  = value;
                buttonRight.Display = value;
             }
          }

          protected override void CreateChildControls()
          {
             Controls.Clear();
             CreateChildControlHierarchy();
          }

          public override ControlCollection Controls
          {
             get
             {
                EnsureChildControls();
                return base.Controls;
             }
          }
          
          private SuperButton buttonLeft ;
          private SuperButton buttonRight;
          private void CreateChildControlHierarchy()
          {
             LiteralControl tableStart = new
                LiteralControl("<table border=1><tr><td>");
             Controls.Add(tableStart);

              buttonLeft = new SuperButton();
             buttonLeft.ID = "buttonLeft";
             if (Context != null)
             {
                buttonLeft.Text = Context.Server.HtmlEncode("<") + " Left";
             }
             else
             {
                buttonLeft.Text = "< Left";
             }
             buttonLeft.CommandName = "Page";
             buttonLeft.CommandArgument = "Left";
             Controls.Add(buttonLeft);

             LiteralControl spacer = new LiteralControl("&nbsp;&nbsp;");
             Controls.Add(spacer);

             buttonRight = new SuperButton();
             buttonRight.ID = "buttonRight";
             buttonRight.Display = Display;
             if (Context != null)
             {
                buttonRight.Text = "Right " + Context.Server.HtmlEncode(">");
             }
             else
             {
                buttonRight.Text = "Right  >";
             }
             buttonRight.CommandName = "Page";
             buttonRight.CommandArgument = "Right";
             Controls.Add(buttonRight);

             LiteralControl tableEnd = new
                LiteralControl("</td></tr></table>");
             Controls.Add(tableEnd);
          }
       }
    }
  • 相关阅读:
    linux网络编程 inet_aton(); inet_aton; inet_addr;
    linux网络编程 ntohs, ntohl, htons,htonl inet_aton等详解
    linux C++ scandir 的使用
    linux 多线程编程-读写者问题
    为什么修改头文件make不重新编译
    syslog(),closelog()与openlog()--日志操作函数
    VC:CString用法整理(转载)
    VC6.0实用小技巧
    HTml js 生成图片
    C++中两个类相互包含引用问题
  • 原文地址:https://www.cnblogs.com/shihao/p/2498654.html
Copyright © 2011-2022 走看看