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

Code without Code Behind

Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
4 Dec 2010CPOL13 min read 24.3K   420   16  
Developing a web based event calendar in ASP.NET using MVP Design Pattern
// Author - Anshu Dutta
// email - anshu.dutta@gmail.com
using System;
using EventCalendar.Presenter;
using System.Web;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EventCalendar.Webservice
{
    public class Events:IHttpHandler,IEventCalendarView
    {       
        private string _selectedYear;
        private EventCalendarPresenter _presenter;
        private HttpContext _context;

        public Events()
        {
            _presenter = new EventCalendarPresenter(this);
        }
        bool IHttpHandler.IsReusable
        {
            get { throw new NotImplementedException(); }
        }

        void IHttpHandler.ProcessRequest(HttpContext context)
        {
            // Expect URl - http://servername.com/VirtualDirectory/EventCalendar?year=selectedYear
            // example - http://localhost/EventCalendarWebService/EventCalendar?year=2010            
            
            _context = context;
            
            _presenter = new EventCalendarPresenter(this);
            _selectedYear = context.Request["year"];
            if (_selectedYear == null)
            {
                _selectedYear = Convert.ToString(DateTime.Now.Year);
            }
            _presenter.UpdateView();
        }      

        string IEventCalendarView.SelectedYear
        {
            get
            { return _selectedYear; }            
        }

        string IEventCalendarView.HTMLCode
        {            
            set
            { _context.Response.Write(value); }
        }        
    }
}

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)
Australia Australia
I am a Senior Software Developer / Technical Consultant in a leading software company.

Comments and Discussions