SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2009
    Location
    A city equidistant from two coasts of India.
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Where should I keep methods called on Button_Click() ?

    This question is from a Best Practices perspective.

    I am using Micro-ORM to separate DAL with Views. I am often confused on my application design approach. While the Micro-ORM takes care of the separation of layers, I also want separation of business logic.

    It is suggested to use Classes in this regard, but use of Classes is puzzling in itself.

    For example, I have a Web Form with a Button. On click of this button, I want to call a method called as: AddCompany.

    I want to know where should I keep this AddCompany method. If it is residing in the .cs file of the Web Form, the business logic is again tightly coupled.

    And if I move this method to a Class, I need to pass all the Web Form input box values as parameters to this class.

    What is the best way to do this?

  2. #2
    SitePoint Wizard webcosmo's Avatar
    Join Date
    Oct 2007
    Location
    Boston, MA
    Posts
    1,480
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    people usually keep the common functions in a business logic layer.

    for example have a function on business logic layer that takes parameters, calls the database stored procedure to complete the job.

    the button click is usually kept on the code behind file(cs in your case). the click function will simply call the business logic layer function to complete the job.

    the idea here is reuse.

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2009
    Location
    A city equidistant from two coasts of India.
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Quote Originally Posted by webcosmo View Post
    people usually keep the common functions in a business logic layer.

    for example have a function on business logic layer that takes parameters, calls the database stored procedure to complete the job.

    the button click is usually kept on the code behind file(cs in your case). the click function will simply call the business logic layer function to complete the job.

    the idea here is reuse.

    If a Web Form contains many input controls then that many parameters need to be passed to the constructor of business layer class.

  4. #4
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,638
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    You don't need to pass the input controls -- you need to pass the input.

    In most cases, we have business layer service classes which take dependencies in the constructor -- such as a database connection or a reference to a repository. Then they have methods that take classes as parameters. Typically these classes are pretty dumb data transfer objects, but they definitely don't reference the controls.

    For ASP.NET webforms, in most cases you'll have to write some code to map the data coming into the form into the class.

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2009
    Location
    A city equidistant from two coasts of India.
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wwb_99 View Post
    You don't need to pass the input controls -- you need to pass the input.
    For ASP.NET webforms, in most cases you'll have to write some code to map the data coming into the form into the class.
    Can you provide little code?

  6. #6
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,638
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Seriously? You do know how to do variable assignment, right?


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •