Click here to Skip to main content
15,881,172 members
Articles / Web Development / ASP.NET

DaST Concept: A simpler, smarter, and much more powerful alternative to Forms and MVC.

Rate me:
Please Sign up or sign in to vote.
4.65/5 (15 votes)
12 May 2011CPOL35 min read 70.5K   433   28  
Pure HTML templates and uniform codebehind is the future of web development. The article presents ASP.NET DaST Rendering Engine and its underlying DaST concept that brings web apps architecture to a new level getting rid of all problems and complexity related to standard ASP.NET Forms and MVC.
  • VideoLibraryDEMO_1.14.zip
    • VideoLibraryDEMO_1.14
      • App_Code
      • App_Data
      • Bin
        • AspNetDaST.dll
      • Default.aspx
      • Default.aspx.cs
      • Global.asax
      • res
        • CSS
        • jQuery
          • jquery-1.4.4.min.js
          • jquery-ui-1.8.9.custom.min.js
          • Themes
            • le-frog
              • images
                • ui-bg_diagonals-small_0_aaaaaa_40x40.png
                • ui-bg_diagonals-thick_15_444444_40x40.png
                • ui-bg_diagonals-thick_95_ffdc2e_40x40.png
                • ui-bg_glass_55_fbf5d0_1x400.png
                • ui-bg_highlight-hard_30_285c00_1x100.png
                • ui-bg_highlight-soft_33_3a8104_1x100.png
                • ui-bg_highlight-soft_50_4eb305_1x100.png
                • ui-bg_highlight-soft_60_4ca20b_1x100.png
                • ui-bg_inset-soft_10_285c00_1x100.png
                • ui-icons_4eb305_256x240.png
                • ui-icons_72b42d_256x240.png
                • ui-icons_cd0a0a_256x240.png
                • ui-icons_ffffff_256x240.png
              • jquery-ui.custom.css
            • start
              • images
                • ui-bg_flat_55_999999_40x100.png
                • ui-bg_flat_75_aaaaaa_40x100.png
                • ui-bg_glass_45_0078ae_1x400.png
                • ui-bg_glass_55_f8da4e_1x400.png
                • ui-bg_glass_75_79c9ec_1x400.png
                • ui-bg_gloss-wave_45_e14f1c_500x100.png
                • ui-bg_gloss-wave_50_6eac2c_500x100.png
                • ui-bg_gloss-wave_75_2191c0_500x100.png
                • ui-bg_inset-hard_100_fcfdfd_1x100.png
                • ui-icons_0078ae_256x240.png
                • ui-icons_056b93_256x240.png
                • ui-icons_d8e7f3_256x240.png
                • ui-icons_e0fdff_256x240.png
                • ui-icons_f5e175_256x240.png
                • ui-icons_f7a50d_256x240.png
                • ui-icons_fcd113_256x240.png
              • jquery-ui.custom.css
            • sunny
              • images
                • ui-bg_diagonals-medium_20_d34d17_40x40.png
                • ui-bg_flat_30_cccccc_40x100.png
                • ui-bg_flat_50_5c5c5c_40x100.png
                • ui-bg_gloss-wave_45_817865_500x100.png
                • ui-bg_gloss-wave_60_fece2f_500x100.png
                • ui-bg_gloss-wave_70_ffdd57_500x100.png
                • ui-bg_gloss-wave_90_fff9e5_500x100.png
                • ui-bg_highlight-soft_100_feeebd_1x100.png
                • ui-bg_inset-soft_30_ffffff_1x100.png
                • ui-icons_3d3d3d_256x240.png
                • ui-icons_bd7b00_256x240.png
                • ui-icons_d19405_256x240.png
                • ui-icons_eb990f_256x240.png
                • ui-icons_ed9f26_256x240.png
                • ui-icons_fadc7a_256x240.png
                • ui-icons_ffe180_256x240.png
              • jquery-ui.custom.css
            • swanky-purse
              • images
                • ui-bg_diamond_10_4f4221_10x8.png
                • ui-bg_diamond_20_372806_10x8.png
                • ui-bg_diamond_25_675423_10x8.png
                • ui-bg_diamond_25_d5ac5d_10x8.png
                • ui-bg_diamond_8_261803_10x8.png
                • ui-bg_diamond_8_443113_10x8.png
                • ui-bg_flat_75_ddd4b0_40x100.png
                • ui-bg_highlight-hard_65_fee4bd_1x100.png
                • ui-icons_070603_256x240.png
                • ui-icons_e8e2b5_256x240.png
                • ui-icons_e9cd86_256x240.png
                • ui-icons_efec9f_256x240.png
                • ui-icons_f2ec64_256x240.png
                • ui-icons_f9f2bd_256x240.png
                • ui-icons_ff7519_256x240.png
              • jquery-ui.custom.css
            • ui-darkness
              • images
                • ui-bg_flat_30_cccccc_40x100.png
                • ui-bg_flat_50_5c5c5c_40x100.png
                • ui-bg_glass_20_555555_1x400.png
                • ui-bg_glass_40_0078a3_1x400.png
                • ui-bg_glass_40_ffc73d_1x400.png
                • ui-bg_gloss-wave_25_333333_500x100.png
                • ui-bg_highlight-soft_80_eeeeee_1x100.png
                • ui-bg_inset-soft_25_000000_1x100.png
                • ui-bg_inset-soft_30_f58400_1x100.png
                • ui-icons_222222_256x240.png
                • ui-icons_4b8e0b_256x240.png
                • ui-icons_a83300_256x240.png
                • ui-icons_cccccc_256x240.png
                • ui-icons_ffffff_256x240.png
              • jquery-ui.custom.css
            • ui-lightness
              • images
                • ui-bg_diagonals-thick_18_b81900_40x40.png
                • ui-bg_diagonals-thick_20_666666_40x40.png
                • ui-bg_flat_10_000000_40x100.png
                • ui-bg_glass_100_f6f6f6_1x400.png
                • ui-bg_glass_100_fdf5ce_1x400.png
                • ui-bg_glass_65_ffffff_1x400.png
                • ui-bg_gloss-wave_35_f6a828_500x100.png
                • ui-bg_highlight-soft_100_eeeeee_1x100.png
                • ui-bg_highlight-soft_75_ffe45c_1x100.png
                • ui-icons_222222_256x240.png
                • ui-icons_228ef1_256x240.png
                • ui-icons_ef8c08_256x240.png
                • ui-icons_ffd27a_256x240.png
                • ui-icons_ffffff_256x240.png
              • jquery-ui.custom.css
      • VideoLibrary.aspx
      • VideoLibrary.aspx.cs
      • web.config
// VideoLibrary DEMO - DaST Technology Demonstrator
// Copyright (C) 2011 Roman Gubarenko 
// http://www.rgubarenko.net
// 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
// 
// Licence terms for AspNetDaST.dll (in Bin folder) are below.
// 
// ASP.NET DaST Rendering Engine (BETA version)
// Copyright (C) 2011 Roman Gubarenko
// http://www.rgubarenko.net
// 
// Redistribution and use of BETA version of DaST Rendering Engine 
// is permitted in binary form without modification. Only original and
// unmodified .NET dll (AspNetDaST.dll) can be used in your own projects and 
// redistributed. You may not copy, decompile, reverse engineer, disassemble, 
// modify, or create derivative works of the software or any part thereof.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE.
//
// DaST technology dev site: http://www.rgubarenko.net
// My contact email for questions: rgubarenko@gmail.com


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using AspNetDaST.Web;

/// <summary>
/// Summary description for PagerController
/// </summary>
public class PagerController : ScopeController
{
  public override void SetTemplate(SetTemplateArgs template)
  {
    template.Markup = Utils.LoadTemplate("PagerTemplate.htm");
  }

  public override void SetupModel(ControllerModelBuilder model)
  {
    model.SetDataBind(new DataBindHandler(ROOT_DataBind));

    model.HandleAction("NextPage", new ActionHandler(Action_NextPage));
    model.HandleAction("PrevPage", new ActionHandler(Action_PrevPage));

    model.RegisterMethod("UpdatePagerValues", new MethodHandler(UpdatePagerValues));
  }


  private void Action_NextPage(ActionArgs args)
  {
    int startItemIdx = ControlPath.Scope.Param<int>("StartItemIdx");
    int pageSize = ControlPath.Scope.Param<int>("PageSize");
    int itemTotalCount = ControlPath.Scope.Param<int>("ItemTotalCount");

    if (startItemIdx + pageSize <= itemTotalCount)
    {
      startItemIdx = startItemIdx + pageSize;
      ControlPath.Scope.SetParam("StartItemIdx", startItemIdx);

      RaiseAction("NextPage", null);
    }
  }

  private void Action_PrevPage(ActionArgs args)
  {
    int startItemIdx = ControlPath.Scope.Param<int>("StartItemIdx");
    int pageSize = ControlPath.Scope.Param<int>("PageSize");
    int itemTotalCount = ControlPath.Scope.Param<int>("ItemTotalCount");

    if (startItemIdx > 0)
    {
      startItemIdx = startItemIdx - pageSize;
      ControlPath.Scope.SetParam("StartItemIdx", startItemIdx);

      RaiseAction("PrevPage", null);
    }
  }


  private void ROOT_DataBind()
  {
    UpdatePagerValues(null);

    int startItemIdx = CurrentPath.Scope.Param<int>("StartItemIdx");
    int pageSize = CurrentPath.Scope.Param<int>("PageSize");
    int itemCount = CurrentPath.Scope.Param<int>("ItemTotalCount");

    if (startItemIdx >= 0 && pageSize > 0 && itemCount > 0)
    {
      int currPage = startItemIdx / pageSize + (startItemIdx % pageSize == 0 ? 0 : 1); ;
      int pageCount = itemCount / pageSize + (itemCount % pageSize == 0 ? 0 : 1);

      CurrentPath.Scope.Replace("{PrevPageIdx}", currPage > 0 ? currPage - 1 : 0);
      CurrentPath.Scope.Replace("{NextPageIdx}", currPage + 1);
      CurrentPath.Scope.Replace("{CurrPageNum}", currPage + 1);
      CurrentPath.Scope.Replace("{TotalPageCount}", pageCount);

      CurrentPath.Fwd("PrevEnabled").Scope.Replace("{PrevPageIdx}", currPage > 0 ? currPage - 1 : 0);
      CurrentPath.Fwd("NextEnabled").Scope.Replace("{NextPageIdx}", currPage + 1);

      if (currPage > 0)
      {
        CurrentPath.Fwd("PrevEnabled").Scope.RenderType = ScopeRenderType.Normal;
        CurrentPath.Fwd("PrevDisabled").Scope.RenderType = ScopeRenderType.None;
      }
      else
      {
        CurrentPath.Fwd("PrevEnabled").Scope.RenderType = ScopeRenderType.None;
        CurrentPath.Fwd("PrevDisabled").Scope.RenderType = ScopeRenderType.Normal;
      }

      if (currPage < pageCount - 1)
      {
        CurrentPath.Fwd("NextEnabled").Scope.RenderType = ScopeRenderType.Normal;
        CurrentPath.Fwd("NextDisabled").Scope.RenderType = ScopeRenderType.None;
      }
      else
      {
        CurrentPath.Fwd("NextEnabled").Scope.RenderType = ScopeRenderType.None;
        CurrentPath.Fwd("NextDisabled").Scope.RenderType = ScopeRenderType.Normal;
      }
    }
    else
    {
      CurrentPath.Scope.RenderType = ScopeRenderType.Empty;
    }
  }


  private object UpdatePagerValues(object jsonData)
  {
    int startItemIdx, pageSize, itemTotalCount;
    if (DaSTUtils.HasValue("StartItemIdx", jsonData)) startItemIdx = (int)DaSTUtils.GetValue("StartItemIdx", jsonData);
    else startItemIdx = ControlPath.Scope.Param<int>("StartItemIdx", 0);
    if (DaSTUtils.HasValue("PageSize", jsonData)) pageSize = (int)DaSTUtils.GetValue("PageSize", jsonData);
    else pageSize = ControlPath.Scope.Param<int>("PageSize", 1);
    if (DaSTUtils.HasValue("ItemTotalCount", jsonData)) itemTotalCount = (int)DaSTUtils.GetValue("ItemTotalCount", jsonData);
    else itemTotalCount = ControlPath.Scope.Param<int>("ItemTotalCount", 0);

    startItemIdx = Math.Min(startItemIdx, itemTotalCount - 1);
    startItemIdx = ((int)(startItemIdx / pageSize)) * pageSize;
    
    // set recalculated values
    ControlPath.Scope.SetParam("StartItemIdx", startItemIdx);
    ControlPath.Scope.SetParam("PageSize", pageSize);
    ControlPath.Scope.SetParam("ItemTotalCount", itemTotalCount);

    return null;
  }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Canada Canada
Software Architect with over 15 years in IT field. Started with deep math and C++ Computer Vision software. Currently in .NET and PHP web development. Creator of DaST pattern, open-source frameworks, and plugins. Interested in cutting Edge IT, open-source, Web 2.0, .NET, MVC, C++, Java, jQuery, Mobile tech, and extreme sports.

Comments and Discussions