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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:08:44+00:00 2026-05-26T08:08:44+00:00

My problem is I’m trying to add user controls to a page dynamically after

  • 0

My problem is I’m trying to add user controls to a page dynamically after clicking a button. Sounds pretty straight forward. Essentially there’s a text field with an add button next to it, on the add button click I want to set the text box to readonly and retain the text, change the add button to a remove and add a new text field and add button below. In essence give the ability to add multiple items to a list.

The solution I came up with is on the add button click, I add the word in the text box to a List that contains all the words the user has already inputted then add the List to the Session. When the postback occurs I just grab the List from the Session and repopulate the already added textboxes. The problem is that is in the ASP .NET page life cycle the button click event actually happens AFTER the page load event so if I try to add the textboxes by grabbing the List in the Session it hasn’t been populated. Conversely if I try to add the textboxes in the page load complete event the button events don’t fire when they’re clicked on (not exactly sure why this is, but is likely because events are bound to buttons somewhere between these two events).

So after poking around a bit it looks like this isn’t possible with just ASP.NET and C# but there may be a way to do this with javascript. Anyone have some insight on how to do this? I’m pretty familiar with C# and ok with javascript but am pretty new to ASP .NET so any help would be appreciated.

  • 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-26T08:08:44+00:00Added an answer on May 26, 2026 at 8:08 am

    You can accomplish your functionality with JQuery as in this jsFiddle

    HTML

    <div id="myDiv">
        <div id="item1">
            <input id="txt1" name="txt1" type="text"></input><input id="cmdAdd1" type="button" value="Add"></input>
        </div>
    </div>
    

    Javascript

    var itemCount = 1;
    $('#cmdAdd1').click(function(){addNewItem();});
    
    function addNewItem(){
        var thisItem = itemCount;
        // Make last text box readonly
        $('#txt' + itemCount).attr('readonly', 'readonly');
        // Change button to Remove button
        $('#cmdAdd' + itemCount).attr('value', 'Remove');
        $('#cmdAdd' + itemCount).unbind();
        $('#cmdAdd' + itemCount).click(function(){removeItem(thisItem );}); 
    
        // Add new line with text field and button
        itemCount++;
        var newItem = '<div id="item' + itemCount + '">'
        newItem += '<input id="txt' + itemCount + '" name="txt' + itemCount + '" type="text"></input>';
        newItem += '<input id="cmdAdd' + itemCount + '" type="button" value="Add"></input>';
        newItem += "</div>";
    
        $('#myDiv').append(newItem);
        $('#cmdAdd' + itemCount).click(function(){addNewItem();});    
    }
    
    function removeItem(i){
        $('#item' + i).remove();
    }
    

    Once your form has posted back to the server, you can iterate through the fields by walking the Form controls.

    C#

    int n=1;
    while (Request["txt" + n] != null)
    {
        Console.WriteLine(Request["txt" + n]);
        n++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

?Problem is pretty simple, I extend Button to create ImageButton, and I extend ButtonSkin
Problem: Widget 'A' is a toplevel window that is displayed after a button click
Problem: I have 2 classes, DB class and a User class, that will work
Problem : Need onclick event to pause/unpause a Youtube video, but impossible to add
Problem: I have a large Visual C++ project that I'm trying to migrate to
Problem: I'm attempting to disable a radio button by using the code below. This
Problem, simple and annoying. Im just trying to print a list of names, collected
Problem: user made some selection in the multi-selection listbox, then pressed a checkbox, and
Problem: Trying to create a Mix that is applied to the AVPlayerItem, but it
Problem description : I'm trying to define a pl/python aggregator that receives a set

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.