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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:47:10+00:00 2026-05-26T11:47:10+00:00

I add a custom user control to my page, with textboxes and radioboxes, but

  • 0

I add a custom user control to my page, with textboxes and radioboxes, but after each postback, the contents are removed and I don’t know how to read the values that were entered in it.

From what I’ve learned you have to add the user controls on each refresh, but that does not restore their state. I want the values to be stored in the ViewState but that does not happen for some reason.

Note: I need to add multiple user controls on one page, so I need to identify each user control, either trough an ID or a linq expression that selects that user control from my page.

Im programming with C# 4.0

How I add my user control:

    private void AddInstrumentDetailToPage()
    {
        RMAItem lItem = (RMAItem)Page.LoadControl("/Controls/RMAItem.ascx");
        InstrumentDetail.Controls.Add(lItem);
    }

I save the amount of controls I have in the ViewState, and call AddInstrumentDetail() that amount of times, but they appear to be empty. I’ve read somewhere that I have to add it in Page_Init because view state is not initialised yet, but that doesn’t help either.

  • 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-26T11:47:10+00:00Added an answer on May 26, 2026 at 11:47 am

    You need to recreate dynamically added (User-)Controls at latest in Page_Load to maintain ViewState. So you should store the number of already added controls in a ViewState-Property and according to that reload them in Page_Load. You have to sum up this variable with 1 in AddInstrumentDetailToPage.

    MSDN: Dynamically Adding User Controls

    If you store the number of added controls in a Viewstate variable, you cannot recreate controls in Page’s Init-Event because the ViewState-Variable would yet not been reloaded there.

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

Sidebar

Related Questions

I'm dynamically adding a custom user control to the page as per this post
I have a custom user control that fires an exception when trying to add
Currently if I want to test a user control, I add my custom tags
I have hard time to modify a page that had a Custom User Control
I want to add a user control to my pages without page post backs.
I have stack panel with custom controls in it. User can add or remove
I am trying to add a custom field to the user form in the
I would like to add some custom data to an image the user generates
I'd like to add custom controls to the mediaPlayer control view much as this
I want a create a custom/user control that has children. For Example, I want

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.