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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:53:06+00:00 2026-05-23T17:53:06+00:00

I have a user control and it has a method which is executed when

  • 0

I have a user control and it has a method which is executed when button on aspx page is clicked, I m passing two ids of the user control in the method, Now i want to get the values of the textbox in the user control but unfortunately it is not recognizing textbox I have coded :-

 //Method to copy values from one control into another
        public void copyInfo(Control ctrl1, Control ctrl2) {  
            List<string> vals = new List<string>();
            foreach (Control c in ctrl1.Controls)
            {
                if (c is TextBox)
                {    
                    if (string.IsNullOrEmpty(((TextBox)c).Text)) { }
                    else {
                   //values from textbox
                        vals.Add(((TextBox)c).Text);
                    }
                }

                              .............
                                ..........
                                  ......

how can i get the textbox control and there values.

  • 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-23T17:53:06+00:00Added an answer on May 23, 2026 at 5:53 pm

    I would add a public property on your UserControl such as:

    public string SomeTextboxValue
    {
      get
      {
        return SomeTextBox.Text;
      }
    
      set
      {
        SomeTextBox.Text = value;
      }
    }
    

    Then you need to cast your controls into their actual types rather than the generic Control class:

    SomeControl someControl1 = (SomeControl)ctrl1;
    SomeControl someControl2 = (SomeControl)ctrl2;
    someControl1.SomeTextboxValue = someControl2.SomeTextboxValue;
    

    Or the other way around depending on which your from and dest are in the copy.

    Update to discuss dynamic controls

    If your controls are being dynamically created and you can’t find it on postback its probably because you haven’t recreated the controls on postback. I have found this article series to be very interesting when trying to understand how to work with and process data from dynamic controls:

    • https://web.archive.org/web/20211020150032/https://www.4guysfromrolla.com/articles/090308-1.aspx

    That link is to part three but its where the important part is which covers your scenario:

    Creating the Custom Client Attribute UI and Loading the Client’s
    Current Values from the Database

    When programmatically adding Web controls to an ASP.NET page it is
    essential that the controls are added to the page on each and every
    page visit
    . This includes the first page visit and all subsequent
    postbacks.

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

Sidebar

Related Questions

I have user control named DateTimeUC which has two textboxes on its markup: <asp:TextBox
I have a user control which has several radiobuttons and buttons... I have code
I have a web browser control which has navigated to a given page and
I have a user control which contains a textbox. I have a class called
I have a drop down which has a method which binds data to it:
I have a User Control that has some WinForm Controls inside. I want to
I am using an ASP.Net Web Application project. I have a user control which
I have a custom UI control which has a JavaScript class written around the
I have a base UserControl (BaseControl.cs) which has an OK and Cancel buttons on
I have a Page that has a single instance of a UserControl that itself

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.