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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:24:15+00:00 2026-05-23T13:24:15+00:00

How do I get properties (e.g. Text ) with asp.net controls that were created

  • 0

How do I get properties (e.g. Text) with asp.net controls that were created programatically when page loading when IsPostBack parameter is true?

Schema:

  • creating control (e.g. TextBox box = new TextBox(); box.ID = "BoxID")
  • display control in page (e.g. SomeControlInPageID.Controls.Add(box))
  • user see this textbox (with id "BoxID", but we don’t have a possibility to get text property use BoxID.Text, because it control was created programatically!) in page & puts in it some text
  • user click in button (asp:Button) in page and start page reloading process
  • start Page_Load method & IsPostBack parameter takes the true value
  • i try to use this code to get Text property in Page_Load method, but it’s not work…:

    void Page_Load()
    {
       if (Page.IsPostBack)
       {
        TextBox box = SomeControlInPageID.FindControl("BoxID") as TextBox;
        string result = box.Text;
       }
       else
       {
        // creating controls programatically and display them in page
        ...
       }
    }
    

box.Text in this code always takes null value.

  • 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-23T13:24:15+00:00Added an answer on May 23, 2026 at 1:24 pm

    The key here is you need to make sure you recreate the dynamic controls each time the page is loaded. Once the controls are created, ASP.NET will be able to fill the posted back values into those controls. I’ve included a full working example below. Notice I add the control in the OnInit event (which will fire before Page_Load), and then I can read the value back out in the Page_Load event if a postback has occurred.

    <%@ Page Language="C#" AutoEventWireup="true" %>
    <html>
    <body>
        <form id="form1" runat="server">
        <asp:Panel ID="myPanel" runat="server" />
        <asp:Button ID="btnSubmit" Text="Submit" runat="server" />
        <br />
        Text is: <asp:Literal ID="litText" runat="server" />
        </form>
    </body>
    </html>
    <script runat="server">
    protected void Page_Load(object sender, System.EventArgs e)
    {
        if(Page.IsPostBack)
        {
            var myTextbox = myPanel.FindControl("myTextbox") as TextBox;
            litText.Text = myTextbox == null ? "(null)" : myTextbox.Text;
        }
    }
    
    protected override void OnInit(EventArgs e)
    {
        AddDynamicControl();
        base.OnInit(e);
    }
    
    private void AddDynamicControl()
    {
        var myTextbox = new TextBox();
        myTextbox.ID = "myTextbox";
        myPanel.Controls.Add(myTextbox);
    }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get an entity with its sub-properties. How can I do that
Is there a way to get XmlSerialization in .NET to ignore certain properties while
Is there a way to get the values of various properties of (both .NET
I need to loop through all controls on ASP.NET webpage. In configuration file I
I'm attempting to query AD in an ASP.Net (4.0) application that is running on
I have an ASP.NET text control FromDate whose visible property is set to false,
I am loading the styles dynamically from the database in my asp.net mvc (C#)
I'm using a bunch of different asp.net validation controls on a web form. Some
I'm trying to get a bare-bones example of logging going in my ASP.NET application.
Can these two properties of a dropdown list in ASP.NET be used independently? I

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.