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

Fast Postback and Model Binding

Rate me:
Please Sign up or sign in to vote.
4.86/5 (28 votes)
27 Apr 2014CPOL6 min read 37.1K   989   37  
Faster way to save data on postback and simplified model binding with ASP.NET controls
<%@ Page Title="Model Binding and Fast Postback" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="FastPostback._Default" %>

<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
    <section class="featured">
        <div class="content-wrapper">
            <hgroup class="title">
                <h1><%: Title %></h1> <br />
                <h2>Simplified model binding with asp.net controls &amp; faster way to save data on postback.</h2>
            </hgroup>
            <p>
                This sample provides you an extermely simplified way to bind models both way with controls in asp.net web form and faster way to Save data
                by avoiding un-necessary events during postbacks. <br />
                This sample performs a basic CRUD operation on Employee table of the database. Click on the "Employee" link and debug to see how it
                binds data and take advantage of a generic handler to avoid life cycle involved during postback when not needed.
            </p>
        </div>
    </section>
</asp:Content>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <h3>This example explains the following:</h3>
    <p>Click on the <asp:HyperLink runat="server" NavigateUrl="~/Employee/List.aspx" Text="Employee"></asp:HyperLink> to view the demo.</p>
    <ol class="round">
        <li class="one">
            <h5>Automatic Model Binding</h5>
            This sample provides you a simplified way to bind your model with your asp.net server controls.
            The example provides you on how you can bind it for TextBox, HiddenField and DropDownList. 
            You may extend this example to bind all other controls.
        </li>
        <li class="two">
            <h5>Postback</h5>
            When asp.net MVC came to the market, many developers simply had switched to MVC because they have seen two major flaws in asp.net WebForm architecture.
            1. Testability and 2. Postback model. While other stuffs like ViewState, Static Control Ids was easy to overcome but postback model and testability was 
            hard to replace. <br />
            This sample provides you an easy way to work around on how you can omit all un-necessary life cycle events simply by using 
            Generic Handler instead of posting data back to the same page. Side by Side you will be able to retain the beauty and flexibility of LifeCycle of your 
            page for first time load or when ever needed. In this approach, you don't need to abondon any rich Server Side Controls which is designed to 
            provide you a huge set of flexibility and Rapid Application Development.
        </li>
    </ol>
</asp:Content>

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
Architect
India India
Anurag Gandhi is a Freelance Developer and Consultant, Architect, Blogger, Speaker, and Ex Microsoft Employee. He is passionate about programming.
He is extensively involved in Asp.Net Core, MVC/Web API, Node/Express, Microsoft Azure/Cloud, web application hosting/architecture, Angular, AngularJs, design, and development. His languages of choice are C#, Node/Express, JavaScript, Asp .NET MVC, Asp, C, C++. He is familiar with many other programming languages as well. He mostly works with MS SQL Server as the preferred database and has worked with Redis, MySQL, Oracle, MS Access, etc. also.
He is active in programming communities and loves to share the knowledge with others whenever he gets the time for it.
He is also a passionate chess player.
Linked in Profile: https://in.linkedin.com/in/anuraggandhi
He can be contacted at soft.gandhi@gmail.com

Comments and Discussions