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 8522055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:00:11+00:00 2026-06-11T07:00:11+00:00

I imagine this question has been asked before (hasn’t every question?), but I am

  • 0

I imagine this question has been asked before (hasn’t every question?), but I am struggling with the language necessary to find my way to a solution, so here are some specifics:

I have a web form for updating a single location, e.g. street address, city, state, etc., which is dealt with by having a static location-update form with various asp:TextBoxes which are referenced in the code-behind using their intellisensed controls, e.g. StreetAddressTextBox.Text.

I would like to update this form to work for multiple locations. In the past when I worked with PHP, this meant writing a lot of inline code wherein I wrapped the form-contents in a for-loop over the collection I was rendering, and then referenced each item with some ID="StreetAddressTextBox_<%=locationId%>"-like schema.

I’m currently in the process of doing it this way in ASP.NET, but inline feels dirty, especially because I have to kick a lot of code-behind paradigms I’ve established on other pages where the form-content wasn’t scaling based on a collection. My gut tells me there should be some way to template out a location and do everything in the code-behind, but I’ve yet to stumble upon and example that shows me this in practice.

Thanks for any help in advance.

  • 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-06-11T07:00:13+00:00Added an answer on June 11, 2026 at 7:00 am

    Assuming I understand you correctly it sounds like you should be using a UserControl.

    Basically create a UserControl.ascx file (and VS will generate the UserControl.designer.cs and code-behind classes for you). Then put your input fields in there with no special attributes, like so:

    (Note that I prefer HtmlControls to WebControls, they give cleaner markup and don’t muddy things. I suggest you give them a try):

    <%@ Control blargh %>
    <label for="<%= Street.ClientID %>">Street address</label>
    <input type="text" runat="server" id="Street" /> <br />
    
    <label for="<%= City.ClientID %>">Town / City</label>
    <input type="text" runat="server" id="City" /> <br />
    
    <!-- etc -->
    

    Note how I’m not messing with the id="" attribute of the input controls. Now just register it in your web.config:

    <add tagPrefix="foo" tagName="Address" src="~/Controls/Address.ascx" />
    

    Then in each page that needs an address form (assuming your UserControl is called AddressControl)

    <%@ Page blargh %>
    <p>Enter your address details below:</p>
    <foo:Address runat="server" id="Address" />
    

    Then in your page’s code-behind you can just do this:

     public override void OnLoad(Object sender, EventArgs e) {
          if( Page.IsPostBack ) {
              Validate();
              if( Page.IsValid ) {
                  // get values from a POST
                  String street = this.Address.Street.Value;
                  String city   = this.Address.City.Value;
                  // and so on
              }
          } else {
              // set values if you're retrieving data from a DB or something
              this.Address.Street.Value = "123 Fake Street";
              this.Address.City.Value = "Frying Pan City";
          }
     }
    

    Note how I used the “<%= Street.ClientID %>”-thing. ASP.NET will automatically generate the control names and IDs based on the control’s parent name (and so on, recursively). So the actual HTML input will be rendered like this:

    <label for="Address.Street">Street address</label>
    <input type="text" name="Address_Street" id="Address.Street" />
    

    Note this design and practice only applies to WebForms. ASP.NET MVC is completely different again.

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

Sidebar

Related Questions

I imagine this question has been asked and answered, but I cannot find it.
I could imagine this question has already been asked, but I actually could not
I imagine this is a question that has been asked a thousand times but
Hey guys, I don't know if this question has been asked yet but imagine
First, I know this question has been asked several times before and that in
You're probably thinking this has been asked a million times before but I think
I imagine this has been asked many times but I am having problems with
Please let me know if this has been asked before, I wasn't able to
I would imagine this might use Reflection.Emit, but a similar question on SO only
This is probably a silly question, but here it goes.Imagine you have the following

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.