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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:05:37+00:00 2026-05-15T05:05:37+00:00

I have a PlaceHolder control inside of a ListView that I am using to

  • 0

I have a PlaceHolder control inside of a ListView that I am using to render controls from my code behind. The code below adds the controls:

TextBox tb = new TextBox();
tb.Text = quest.Value;
tb.ID = quest.ShortName.Replace(" ", "");
((PlaceHolder)e.Item.FindControl("ph_QuestionInput")).Controls.Add(tb);

I am using the following code to retrieve the values that have been entered into the TextBox:

foreach (ListViewDataItem di in lv_Questions.Items)
{
    int QuestionId = Convert.ToInt32(((HiddenField)di.FindControl("hf_QuestionId")).Value);
    Question quest = dc.Questions.Single(q => q.QuestionId == QuestionId);
    TextBox tb = ((TextBox)di.FindControl(quest.ShortName.Replace(" ","")));
    //tb is always null!
}

But it never finds the control. I’ve looked at the source code for the page and the control i want has the id:

ctl00_cphContentMiddle_lv_Questions_ctrl0_Numberofacres

For some reason when I look at the controls in the ListViewDataItem it has the ClientID:

ctl00_cphContentMiddle_lv_Questions_ctrl0_ctl00

Why would it be changing Numberofacres to ctl00? Is there any way to work around this?

UPDATE:

Just to clarify, I am databinding my ListView in the Page_Init event. I then create the controls in the ItemBound event for my ListView. But based on what @Womp and MSDN are saying the controls won’t actually be created until after the Load event (which is after the Page_Init event) and therefore are not in ViewState? Does this sound correct?

If so am I just SOL when it comes to retrieving the values in my dynamic controls from my OnClick event?

UPDATE 2:

So i changed the code i had in my Page_Init event from:

protected void Page_Init(object sender, EventArgs e)
{
        if (!this.IsPostBack)
        {
            //databind lv_Questions
        }
}

to:

protected void Page_Init(object sender, EventArgs e)
{
            //databind lv_Questions
}

And it fixed my problem. Still a little confused as to why I want to databind regardless of whether it’s a postback or not but the issue is resolved.

  • 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-15T05:05:37+00:00Added an answer on May 15, 2026 at 5:05 am

    It looks like you’re adding your textbox to a Placeholder control… but then you’re searching a ListViewDataItem container for it later.

    Seems to me that you need to search for the Placeholder first, and then search it for the textbox.

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

Sidebar

Related Questions

I have some code on a User Control that looks like this: <asp:PlaceHolder id=ph1
I have 8 or more Image controls each inside HyperLink and PlaceHolder I need
I have a bit of code that determine whether or not a control (within
I have a control that is a date picker with validation using HTML5's pattern
I have the following user-control: <%@ Control Language=C# AutoEventWireup=true CodeFile=FadingMessage.ascx.cs Inherits=includes_FadingMessage %> <asp:PlaceHolder Visible=false
I have added placeholder to a page as below. <tr > <td > <asp:PlaceHolder
I have A single page that has the following structure <form runat=server><placeholder></placeholder></form> I have
I have a asp DataList that gets populated by a DataTable . <asp:PlaceHolder ID=ph3
actually, i'm developing a web template using ASP.NET and C#. i have a listview
I have only single Default.aspx page and a single ListView Control. Why am 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.