Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 23rd, 2007, 12:56 PM
rlb rlb is offline
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pass WebControls as struct to BLL instead of indiv

Hello,
I am working on a huge web application. I have a Presentation, Business, and Data Access Layer.
In my presentation layer I have some pages that are large forms with many different web controls. When needed, these forms need to be populated or updated into the database. I can either pass all of the appropriate web controls to the Business Layer (which uses the DAL) to do so, or I can consult the BLL for each web control.

My question is, is there a popular design pattern so that one would not be passing web controls all over the place? Specifically, is there anything like this:

Partial Class myWebPage_CodeBehind{

struct myWebPageControls{
TextBox personName;
TextBox personAddress;
DropDownList paymentType;
RadioButtonList genderType;
DropDownList educationLevel;
 // ...
}

public protected void Page_Load(){
   this.getBLLInstance().loadRecordIntoControls(recor dID, myWebPageControls );
}


instead of


public protected void Page_Load(){
   this.getBLLInstance().loadRecordIntoControls(recor dID, personName_textbox, personAddress_textbox, paymentType_ddl, educationLevel_ddl, gendertype_radiolist, ... );
}


Thanks for your help!
 
Old April 23rd, 2007, 01:25 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Somehow, this seems like a design with some issues. Why does a BllInstance have a method called loadRecordIntoControls?

That seems to defeat the whole purpose of layer separation. What happens when you decide to change personAddress from a TextBox to a User Control? Or genderType to a DropDownList? Or am I overlooking something?

You could make helper objects that do this for you, but IMO, you should put those helpers in the presentation layer, and pass it a reference to a BO.

For my take on this issue, check out my article series about N-Layer design that starts here: http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=416

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old April 23rd, 2007, 02:21 PM
rlb rlb is offline
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmm... okay so I can build Business Objects and pass those from the BLL and Presentation layer.

class mywebpage{
  protected void Page_Load(){
     Person myperson = this.getBLL().getPerson(personID);
     //fill out the webpage form with the data we just recieved
     this.person_name_textbox = myperson.getName()
     //etc
  }
}


class mywebpage_BLL{
    public Person getPerson(personID){
         Person p = new Person();
         p.setName(this.getDAL().getName(personID));
         //set more properties, etc, then
         return p;
    }
}


//location: ProjectName/AppCode/BuisnessObjects/Person.cs
class Person{
  //private fields here
  private String name;
  private int personID;
  private String address;
  //public getter and setter methods for fields above
}

I think i get it, this is much easier! Like this, correct? Let me know if I missed anything.
 
Old April 23rd, 2007, 03:35 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

More or less, yes, although you probably don't want to hit the DAL for every property of a BO, but instead return the entire BO at once.

Helper functions in the web layer can then be used to fill controls in the UI.

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.




Similar Threads
Thread Thread Starter Forum Replies Last Post
pointer to struct goscho C++ Programming 1 January 10th, 2008 07:23 AM
WebControls.LinkButton Ric_H ASP.NET 2.0 Basics 1 January 28th, 2006 08:00 AM
Reading webcontrols shellhb ASP.NET 1.x and 2.0 Application Design 0 October 20th, 2005 01:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.