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

Pretty URLs, Separation of Layers and O/R Mapping in Web Forms ASP.NET 2.0

Rate me:
Please Sign up or sign in to vote.
4.47/5 (14 votes)
12 Sep 200732 min read 87K   493   87  
Implementing multi-tier architecture in a web application using ASP.NET 2.0
using System;
using System.Web.UI.WebControls;
using NHibernate.MapClasses;
using System.Collections;


public partial class EditClass : System.Web.UI.Page, MVC.Views.IGeneralView
{

    private MVC.Controllers.IAdminController _controller;
  
    public delegate Product SingleBook_Handler();

    public void Alert(string message)
    {
        notice.Text = message;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack) // on POST
        {
            _controller = MVC.Factories.Factory.PointerToFactory.GetAdminController(this); 
            //only on GET we use selectmethod,on POST--ViewState is used
            // Update method is handled by us independently from ODS !
        }
        else //on GET
        {
            _controller = MVC.Factories.Factory.PointerToFactory.GetAdminController(this); 
            ObjectDataSource1.TypeName = _controller.GetType().FullName;
            SingleBook_Handler GiveMethodName = new SingleBook_Handler(_controller.SingleBook);
            ObjectDataSource1.SelectMethod = GiveMethodName.Method.Name;
            DetailsViewValidated.DataSourceID = "ObjectDataSource1";

        }
    }
    

    protected void Page_PreRender(object sender, EventArgs e)
    {
        //here i set navurl fro two urls
        SetView();
    }

    //this handler is invoked after all other user events
    protected void ObjectDataSource1_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
    {
        if (!IsPostBack) e.ObjectInstance = _controller; //we use the view state on PostBack
    }


    private void SetView()
    {
        //here I set navurl for   CreateGoToAdmin link

        ContentPlaceHolder MasterPlaceH = (ContentPlaceHolder)this.Master.FindControl("MainCol");
        HyperLink EditGoToAdmin = (HyperLink)MasterPlaceH.FindControl("EditGoToAdmin");
        EditGoToAdmin.NavigateUrl = Utils.Utils.GetUrl("action=>admin");
    }




    protected void DetailsViewValidated_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
    {
       
        _controller.UpdateSingleBook(e.Keys,e.OldValues,e.NewValues);
        e.Cancel = true;
    }
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer iPay, Elizabethtown,Ky
United States United States
After defending his PhD thesis in 2005 (computational nuclear physics) at Vanderbilt in Nashville, the author decided to pursue a career in software development. As a long time open source advocate, he started with writing web applications using Linux-Apache-MySql-P (LAMP) framework. After that experience, he decided to embrace Microsoft technologies.
Currently working as a web developer in .NET platform in the online payments company.

Comments and Discussions