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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:12:11+00:00 2026-05-31T05:12:11+00:00

I have a basic TextBox on a user control I am dynamically loading. I

  • 0

I have a basic TextBox on a user control I am dynamically loading. I figured out how to push a value to this TextBox. The problem I am running into is that I can’t get the entered value from this TextBox.

I had to create a class to pass variables to/from the dynamically loaded control. I called it PBUserControl.

public class PBUserControl : UserControl
{
    public IList<NVP> NameValuePairs { get { return _NameValuePairs; } }

    public class NVP
    {
        public NVP() { }
        public NVP(string name, string value)
        {
            this.Name = name;
            this.Value = value;
        }
        public string Name { get; set; }
        public string Value { get; set; }
    }
}

This seems to work just fine for sending data into the user control.

My Dynamically loaded user control:

public partial class Basic : PBUserControl 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (this.IsPostBack == false)
        {
            this.InitializeControl();
        }
        else
        {
            this.ProcessSubmit();
        }
    }

    private void InitializeControl()
    {
        DynamicLiteral.Text = "Some Dynamic Content. " + GetNameValue("TestContent");
        TestTextBox.Text = GetNameValue("Test");
    }
    private void ProcessSubmit()
    {
        AddNameValuePair("TestContent", "Passing back some value... "+ DynamicLiteral.Text);
        AddNameValuePair("Test", TestTextBox.Text);
    }
}

Here is the page calling and including this Dynamically loaded control:

public partial class PageAddEdit : PageBase
{
    private PBUserControl _PBUserControl;

    protected void Page_Load(object sender, EventArgs e)
    {
        // Must always desigante the control here else it dissapears.
        Control TemplateUserControl = LoadControl("~/Administrator/PageBuilder/Templates/Basic.ascx");
        _PBUserControl = (PBUserControl)TemplateUserControl;
        _PBUserControl.AddNameValuePair("TestContent", "It is working!!!!!!!!!");
        _PBUserControl.AddNameValuePair("Test", "Some test text.");
        Template.Controls.Add(TemplateUserControl);
    }

    protected void MenuGroupRadMenu_Clicked(object sender, EventArgs e)
    {
        IList<PBUserControl.NVP> nvp = _PBUserControl.NameValuePairs;
    }
}

Let me explain what is going on here. I can set the values in the PBUserControl from the main page. It passes into the Dynamically loaded user control perfectly. Does what it is supposed to do. Works wonderfully.

However, the page_load event within the dynamically loaded control is being fired before the postback variables are processed. So at that point the contents of the TextBox is not even read yet. I found this out through research. Also, if I put a Pre_Rendered event within the Dynamically loaded control I can see the value of the TextBox when stepping through the code with the debugger. Also, with the debugger I can see that the TextBox is not read during the Page_Load event. My research lead me to the following:
1. Page_Init event is called
2. Page_Load event is called
3. Page form variables are read and processed (Not sure what event)
4. User Events are called ie: OnClick
5. Pre_Rendered event is called.

I need to be able to create an event that will be called after step 3 and before or during step 4. That way I can capture the TextBox value and set it’s value within the PBUserControl.NVP variable so it can be read by the main page. If I manually set a value in the PBUserControl.NVP variable, it is seen by the main page and is read just fine.

Thanks 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-05-31T05:12:11+00:00Added an answer on May 31, 2026 at 5:12 am

    I figured it out!!!! Basically I created an event and passed it from the Dynamically loaded UserControl to the Main UserControl. Below are the changes I made to get it to work. Quick explanation so everyone can follow along with how it works. I have an outer wrapper called PBUserControl that allows me to create some elements through inheriting. The idea behind is to allow me to pass data back and forth and apparently an event. When dynamically loading a child control you are no longer afforded the luxury of easily tying elements nor events. The PBUserControl class creates a common bond that allows this to work. For my purposes it is setup to ideally work for how the data structure is setup on the back end. So making tweaks will be required to make it work for you. But this should prove to be an easy to follow concept.

    I am able to register an action within the dynamic control to the ControlSubmittedHandler located in PBUserControl.

    I am able to register the action from the dynamic control in the parent control by assigning the ControlSubmittedHandler through the ControlSubmittedDelegate into a local event. At that point I am able to trigger that event.

    Enough explanation, here are the code changes to make it work:

    I added the following to the class PBUserControl:

    public delegate void ControlSubmittedDelegate(object sender, EventArgs e);
    public System.EventHandler ControlSubmittedHandler;
    

    Within my dynamically loaded control I changed the Page_Load event to:

    protected void Page_Load(object sender, EventArgs e)
    {
        InitializeControl();
        this.ControlSubmittedHandler = new EventHandler(ControlSubmittedAction);
    }
    

    Within my dynamically loaded control I added:

    public void ControlSubmittedAction(object sender, EventArgs e)
    {
        ProcessSubmit();
    }
    

    Within my main control I added:

    private PBUserControl _PBUserControl;
    private event PBUserControl.ControlSubmittedDelegate myEvent;
    

    Within my main control I changed:

    protected void MenuGroupRadMenu_Clicked(object sender, EventArgs e)
    {
        myEvent = new PBUserControl.ControlSubmittedDelegate(_PBUserControl.ControlSubmittedHandler);
        if (myEvent != null) myEvent(this, e);
    
        IList<PBUserControl.NVP> nvp = _PBUserControl.NameValuePairs;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user control that is pretty basic. It contains several TextBox controls,
I have a basic form with some ASP.NET textbox fields laid out and I
Okay, so, this code is pretty basic. The user inputs an answer into a
I have a basic username textbox. This textbox can be seen here: http://68.71.136.106/test.htm In
I have a basic CRUD form that uses PageMethods to update the user details,
I have a collection in Visual Basic.net (Sorry if people are seeing this code
Looking for some direction here as I'm running into some migration problems. We have
This is probably a basic question, since I'm new to WPF.. I have a
I have made one custom user control (search text box), which basically consists of
I'm new to WPF and still having some basic problems. I have a control

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.