locked
Basic Asp.net design and application architecture question RRS feed

  • Question

  • User357616875 posted

    I have written an asp app, that works like this.

    Everything is 404ed to a single page, with a base class. The base class looks up the requested URL and decides what to display.

    In the 404 page Load Sub, i refer to another sub depending on what needs to be displayed. The base class produces a type code and level value. For example it may product "HO", 1, which using some CASE / SELECTs determines do call the Hotel Level Display Sub.

    In this sub it loads various user controls to display the hotel content page. I have 96 business types with 4 or 5 levels. All though the it is NOT if else if else the base class is now massive.

    If I dont do all the usercontrol in the base class I cant to master.findcontrol and me.this and that because another class would not inherit the ui.page class.

    I seem to be left with two options

    1) use nested user controls and move a lot of the decision logic to the main user control, calling sub user controls based on DB values

    or

    2) Move a lot of the html stuff on to class functions that can be called from the UserControl - I mean at the moment I have a usercontrol that displays the hotel title, rating, and three other things, so I could construct this html in another class and return it to the user control.

    Graham




    Sunday, April 18, 2010 2:38 PM

Answers

  • User-821857111 posted

    You have a third option: use the MVC framework. In the long run, it's going to be a lot less painful than hacking around with what you currently have. At the moment, it sounds like you have already employed a similar approach, but with one almighty controller (your base class) managing the whole application.

    In the meantime, you can combine your existing app with MVC as you move parts across.

    http://www.packtpub.com/article/mixing-asp.net-webforms-and-asp.net-mvc


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 18, 2010 5:12 PM
  • User-952121411 posted

    I was thinking the same thing as Mike from the previous response - in the MVC pattern the 'Controller' is designed to solve the complex problem that you are facing.  Read below an excerpt from the MSDN:

    "Controllers. Controllers are the components that handle user interaction, work with the model, and ultimately select a view to render that displays UI. In an MVC application, the view only displays information; the controller handles and responds to user input and interaction. For example, the controller handles query-string values, and passes these values to the model, which in turn might use these values to query the database. "

    http://msdn.microsoft.com/en-us/library/dd381412.aspx

    ...from Scott Guthrie's Blog:

    "Controllers" in a MVC based application are the components responsible for handling end user interaction, manipulating the model, and ultimately choosing a view to render to display UI.  In a MVC application the view is only about displaying information - it is the controller that handles and responds to user input and interaction.

    ...and from Design Patterns: Elements of Reusable Object Oriented Software:

    "MVC also lets you change the way a view responds to user input without changing its visual presentation. You might want to change the way it responds to the keyboard, for example, or have it use a pop-up menu instead of command keys. MVC encapsulates the response mechanism in a Controller object. There is a class hierarchy of controllers, making it easy to create a new controller as a variation on an existing one.

    A view uses an instance of a Controller subclass to implement a particular response strategy; to implement a different strategy, simply replace the instance with a differentkind of controller. It's even possible to change a view's controller at run-time to let the view change the way it responds to user input. For example, a view can be disabled so that it doesn't accept input simply by giving it a controller that ignores input events."

    You may not have time to convert at this point, but it is something to consider since your application sounds quite large.  In the interm either one of your posted solutions might have to be the solution.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 19, 2010 2:27 PM

All replies

  • User-821857111 posted

    You have a third option: use the MVC framework. In the long run, it's going to be a lot less painful than hacking around with what you currently have. At the moment, it sounds like you have already employed a similar approach, but with one almighty controller (your base class) managing the whole application.

    In the meantime, you can combine your existing app with MVC as you move parts across.

    http://www.packtpub.com/article/mixing-asp.net-webforms-and-asp.net-mvc


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 18, 2010 5:12 PM
  • User-952121411 posted

    I was thinking the same thing as Mike from the previous response - in the MVC pattern the 'Controller' is designed to solve the complex problem that you are facing.  Read below an excerpt from the MSDN:

    "Controllers. Controllers are the components that handle user interaction, work with the model, and ultimately select a view to render that displays UI. In an MVC application, the view only displays information; the controller handles and responds to user input and interaction. For example, the controller handles query-string values, and passes these values to the model, which in turn might use these values to query the database. "

    http://msdn.microsoft.com/en-us/library/dd381412.aspx

    ...from Scott Guthrie's Blog:

    "Controllers" in a MVC based application are the components responsible for handling end user interaction, manipulating the model, and ultimately choosing a view to render to display UI.  In a MVC application the view is only about displaying information - it is the controller that handles and responds to user input and interaction.

    ...and from Design Patterns: Elements of Reusable Object Oriented Software:

    "MVC also lets you change the way a view responds to user input without changing its visual presentation. You might want to change the way it responds to the keyboard, for example, or have it use a pop-up menu instead of command keys. MVC encapsulates the response mechanism in a Controller object. There is a class hierarchy of controllers, making it easy to create a new controller as a variation on an existing one.

    A view uses an instance of a Controller subclass to implement a particular response strategy; to implement a different strategy, simply replace the instance with a differentkind of controller. It's even possible to change a view's controller at run-time to let the view change the way it responds to user input. For example, a view can be disabled so that it doesn't accept input simply by giving it a controller that ignores input events."

    You may not have time to convert at this point, but it is something to consider since your application sounds quite large.  In the interm either one of your posted solutions might have to be the solution.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 19, 2010 2:27 PM