Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 707785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:19:02+00:00 2026-05-14T04:19:02+00:00

I have a ASP.NET Web Forms application and I’m using some dynamic controls in

  • 0

I have a ASP.NET Web Forms application and I’m using some dynamic controls in the view which depend on stuff that the presenter exposes. Is it okay for the view in this case to pull on the presenter for that data? Is there anything I should be extra careful about when considering testability and a loosely coupled design.

The page in this case has it’s own page-life cycle and the presenter doesn’t know about this. However, the page-life cycle dictates that somethings must occur at specific moments in the page-life cycle. This smells like trouble… Any known pit falls?

EDIT

When my concrete view hits the Init event it will pull on the presenter for a collection that will result in a bunch of ASP.NET server controls to be created. I’m wondering if this is a particular bad thing to do… The presenter doesn’t know how to respond to the page-life cycle init event but it has to if the view is to be populated with dynamic controls.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:19:02+00:00Added an answer on May 14, 2026 at 4:19 am

    This is a vexing question – when you want dynamic controls in ASP.NET web forms you’ve got to choose the lesser of two evils. Ultimately, it comes down to which compromise you want to make: presenter concerns in the view or view concerns in the presenter.

    When I work in web forms I usually prefer the latter – I accept that the presenter is tied to the ASP.NET page lifecycle and create an InitializeView method to do whatever’s necessary to create dynamic controls:

    // Presenter
    // This could also be parameterless if you prefer that idiom but 
    // then the view needs a SelectedState property that serves up values
    // straight from the Form collection, and it won't be obvious why.
    public void InitializeView(string selectedState) { 
        if (selectedState != null) {
            view.Counties = dataLayer.GetCounties(selectedState);
        }
    }
    
    // View
    protected void Page_Init(object sender, EventArgs args) {
        presenter.InitializeView(Request.Form["StateList"]);
        // ... build counties drop-down ...
    }
    

    Of course, this ties the presenter’s semantics to the ASP.NET lifecycle and obscures what’s going on in that method. You can mitigate that by giving InitializeView a more descriptive name, like ProcessSelectedState, but unless the method name references the page lifecycle, it’s never going to be obvious why you’re not just getting counties with the rest of the model (in presenter.LoadModel or whatever you might call it).

    I can see how the alternative is attractive:

    protected void Page_Init(object sender, EventArgs args) {
        if (Request.Form["StateList"] != null) {
            List<string> counties = presenter.GetCounties(Request.Form["StateList"]);
            // ... build counties drop-down ...
        }
    }
    

    The semantics of the Presenter are perfectly clear – it’s easy to understand what GetCounties does and it doesn’t have anything to do with the page lifecycle. But you have testable stuff in your view, which is a bummer, and that’s usually more important to me than keeping my presenters ignorant of their view engine.

    Another alternative is to just load your entire model during page initialization. Your server control values won’t be available, so you’d have to get any of those from Request.Form. That’s not idiomatic ASP.NET classic though – it might be unduly confusing since most web forms developers are accustomed to getting values directly from web controls instead of directly from the POST data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.Net Web Forms application in which I'm using forms-based authentication with
We have an ASP.NET web forms application which occasionally generates a validation error like
We have been using log4net for logging our asp.net web forms application. Our logging
Using web forms I know that you can only have one ASP.NET form on
We have an ASP.NET web forms application that is probably vulnerable to Cross-site request
I have a ASP.NET Web Forms application that internally makes many SOAP and REST
I have a simple ASP.NET 3.5 SP1 Web Forms app... I've added the System.Web.Routing
I have authentication mode set to forms in my asp.net web.config but am still
I have an ASP.NET web form which I am adding a variable number User
I have an asp.net url path which is being generated in a web form,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.