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

  • SEARCH
  • Home
  • 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 697069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:07:48+00:00 2026-05-14T03:07:48+00:00

I am currently developing some user controls so that I can use them at

  • 0

I am currently developing some user controls so that I can use them at several places within a project. One control is a about editing a list of addresses for a customer. Since this needs to be done at several places within the project I want to make it a simple user control. The user control contains a repeater control. By default the repeater displays one address item to be edited. If more addresses need to be added, the user can click on a button to append an additional address to be entered. The user control should work for creating new addresses as well as editing existing ones.
The address business entity looks something like this:

public class Address
{
    public string Street { get; set; }

    public City City { get; set; }

    public Address(string street, City city)
    {
        Check.NotNullOrEmpty(street);
        Check.NotNull(city);

        Street = street;
        City = city;
    }
}

As you can see an address can only be instantiated if there is a street and a city.

Now my idea was that the user control exposes a collection property called Addresses.
The getter of this property collects the addresses from the repeater and return it in a collection. The setter would databind the addresses to be edited to the repeater.

Like this:

public partial class AddressEditControl : System.Web.UI.UserControl
{

    public IEnumerable<Address> Addresses
    {
        get
        {
            IList<Address> addresses = new List<Address>();
            // collect items from repeater and create addresses
            foreach (RepeaterItem item in addressRepeater.Items)
            {
                // collect values from repeater item

                addresses.Add(new Address(street, city));
            }

            return addresses;
        }
        set
        {
            addressRepeater.DataSource = value;
            addressRepeater.DataBind();
        }
    }
}

First I liked this approach since it is object oriented makes it very easy to reuse the control. But at some place in my project I wanted to use this control so a user could enter some addresses. And I wanted to pre-fill the street input field of each repeater item since I had that data so the user doesn’t need to enter it all by his self.

Now the problem is that this user control only accepts addresses in a valid state (since the address object has only one constructor). So I cannot do:

IList<Addresses> addresses = new List<Address>();
addresses.Add(new Address("someStreet", null)); // i dont know the city yet (user has to find it out)

addressControl.Addresses = addresses;

So the above is not possible since I would get an error from address because the city is null.

Now my question: How would I create such a control? 😉
I was thinking about using an Address DTO instead of a real address, so it can later be mapped to an address. That way I can pass in and out an address collection which addresses don’t need to be valid.
Or did I misunderstood the way user controls work? Are there any best practices?

  • 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-14T03:07:49+00:00Added an answer on May 14, 2026 at 3:07 am

    Directly binding Business Objects (which have strict rules and retricted constructors) to UserControls (which may have to allow data in partial and invalid states) is fraught with danger.

    If you were to use an Address View Model (a view model is a DTO used to talk between the controller and the User Control), then you could allow any old rubbish in the view model, that would have to be validated before it were turned into an Address.

    This also allows separation of the View/UserControl from the Business Layer, so reuse becomes easier.

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

Sidebar

Related Questions

I'm currently developing on a project which uses some TimerJobs. One of the jobs
I am currently developing a Silverlight 3 app that needs some sort of user
I am currently developing a web application in which the user can download some
I'm currently developing a project that at some part calls a number of the
I am currently developing an application that allows the use of plugins. One of
I´m currently developing a Struts2 app where a user will make one of three
I'm currently developing an application that needs to parse some (a big file of)
I am currently developing an android program. After some searching i can't seem to
Currently developing an application for Windows Phone that makes use of the bing maps
I'm currently developing a custom control and realize that my code is being run

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.