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);
          }
       }
    }
  • 相关阅读:
    TSQL循环打印一年中所有的日期(WHILE循环)
    给Table加字段的SQL
    [正则表达式]前台JS得到控件ID (该控件被其它控件包住了)
    1.SQL Server中批量更新Object的Owner 2.附加数据库
    转:动态LINQ的几种方法
    转:查看LINQ生成SQL语句的几种方法
    TrimZero方法
    Oracle关联更新语法(TSQL中的update...from)
    Table之间的空隙或Table与父控件之间的空隙怎么去掉?
    自动完成带来的麻烦
  • 原文地址:https://www.cnblogs.com/shihao/p/2498654.html
Copyright © 2011-2022 走看看