Welcome to weblogs.com.pk Sign in | Join | Help

Object Data Source Controls :: Page Maintenance

With Data Source Controls in ASP.NET v2; things are turning into declarative programming style; more code is being pushed to UI (ASPX/ASCX) and with that; runtime errors increases; especially in maintenance phase of the software. If you want to learn how object data source controls can help you develop web apps rapidly; read Nasir's Introduction to Object Data Source in ASP.NET 2.0

Managing object data sources; their binding with your data gateway classes and data bound controls can be nightmare. My colleagues have reached almost middle of the development; and going ahead; they are facing similar problems. In a recent discussion we talked about this. I mentioned this post that has discussed this. A snap from that article is attached.

I sat down that same evening and tried implementing some thing to get my hands dirty.

  • Use custom data objects; don’t use DataTables/DataSet; as when you use them; the design time experience can be bad if your gateway class needs to be instantiated with parameters at construction time. In my example; I was connecting to IMAP based email store and for that I need to provide login/password of the mailbox. My understanding is; when you are using DataTables/DataSet; the designer executes the method to get the metadata what has been return to show you how you want to bind things with controls like Grid View. When you are using custom data objects; metadata is readily available; and the actual method doesn’t get executed. So for my simple app; I used the following two data objects.


    Custom Data Objects



    Data Gateway Class

  • There is two type of code in ASPX/ASCX that can be troublesome to maintain; one is for declaring the types and names of the gateway class methods and second is declaration of parameters being passed to Select/Update/Insert/Delete methods. We should have these declarations in the code behind file in Page_Init() method; to improve things a little; we may define these as constants in our gateway class and use those constants in the code behind; doing this; chances of runtime errors decreases; as things are defined in constants which are closer to the actual code and developer/maintainer will not forget updating them when anything get changed.

     
    Page_Init in code behind

     
    The ASCX
Published Sunday, March 19, 2006 4:46 PM by khurram
Filed under:

Comments

No Comments

New Comments to this post are disabled