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

  • Home
  • SEARCH
  • 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 4245766
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:53:01+00:00 2026-05-21T03:53:01+00:00

I’m creating textboxes in the Page_Load event and giving them values, however whenever I

  • 0

I’m creating textboxes in the Page_Load event and giving them values, however whenever I load the details I am getting the same output. I always seem to get the first output I got, even on subsequent searches.

Here’s what my code with the irrelevant information missing:

Textbox txtName = New Textbox();
protected void Page_Load(object sender, EventArgs e)
{
    LoadData();
}

void LoadData()
{
    txtName.Text = DropDownList.SelectedValue;
    tableCell.Controls.Add(txtName);
}

If DropDownList has two values (e.g. “Item 1” and “Item 2”) and has autopostback enabled, first time it will generate and show “Item 1” in the textbox (the default value for the DropDownList), but if this is changed and the autopostback fires, the textbox does not change.

I’ve tried getting around this by creating a new TextBox, overriding the “LoadPostData” function to prevent this from loading, which got around the issue there, but then I couldn’t view the data afterwards.

Any idea how I could get around this? I may be approaching this in the wrong way.

Edit: I’ve added another item to DropDownList that removes TextBox, so that it can be re-created again. It seems to show the correct data when it is re-created after being removed, but if I’m attempting to just edit it, this isn’t updating correctly.

Edit2: Here’s the rest of the code for this page in case this helps at all. The objects which I’m having issues with are SBUName and SBUComments, which are both TextBoxes. The same issue is also happening for SBUClientDropdown but I believe the resolution will be similar:

DBHandler DBHandler = new DBHandler();
List<string> clients = new List<string>();
List<string> clientGroups = new List<string>();
List<string> sbus = new List<string>();

// Objects for SBU changes
string previousSBU = "";
string previousSBUClient = "";
TextBox SBUName = new TextBox() { ID = "SBUName" };
TextBox SBUComments = new TextBox() { ID = "SBUComments" };
DropDownList SBUClientDropdown = new DropDownList();

protected void Page_Load(object sender, EventArgs e)
{
    clients = DBHandler.GetClients();
    clientGroups = DBHandler.GetClientGroups();

    if (!Page.IsPostBack)
    {
        foreach (string client in clients)
        {
            SBUClientList.Items.Add(GenerateItem(client));
            ClientList.Items.Add(GenerateItem(client));
        }

        foreach (string clientGroup in clientGroups)
            ClientGroupList.Items.Add(GenerateItem(clientGroup));
    }

    if ((SBUClientList.SelectedValue.ToString() != previousSBUClient) || (SBUList.SelectedValue.ToString() != previousSBU))
    {
        previousSBUClient = SBUClientList.SelectedValue.ToString();
        previousSBU = SBUList.SelectedValue.ToString();

        sbus = DBHandler.GetSBUs(SBUClientList.SelectedValue);
        SBUList.Items.Clear();
        foreach (string sbu in sbus)
            SBUList.Items.Add(GenerateItem(sbu));

        LoadSBU();
    }
}

void LoadSBU()
{
    if ((SBUClientList.SelectedValue.Trim().Length > 0) && (SBUList.SelectedValue.Trim().Length > 0))
    {
        Entity thisSBU = DBHandler.GetSBUInformation(SBUClientList.SelectedValue, SBUList.SelectedValue);

        SBUTable.Rows.Add(GenerateHeaderRow("Client Name", "SBU Name", "Comments"));

        SBUClientDropdown.Items.Clear();
        foreach (string client in clients)
            SBUClientDropdown.Items.Add(GenerateItem(client));
        SBUClientDropdown.SelectedValue = SBUClientList.SelectedValue;
        SBUClientDropdown.SelectedIndex = SBUClientList.SelectedIndex;
        TableCell SBUClientCell = new TableCell();
        SBUClientCell.Controls.Add(SBUClientDropdown);


        SBUName.Text = thisSBU.sSBUName;
        TableCell SBUNameCell = new TableCell();
        SBUNameCell.Controls.Add(SBUName);


        SBUComments.Text = thisSBU.sSBUComments;
        TableCell SBUCommentsCell = new TableCell();
        SBUCommentsCell.Controls.Add(SBUComments);

        SBUTable.Rows.Add(GenerateRow(SBUClientCell, SBUNameCell, SBUCommentsCell));

        Button SBUSaveButton = new Button();
        SBUSaveButton.Click += new EventHandler(this.SBUSaveChanges);
        SBUSaveButton.Text = "Save SBU Changes";
        TableCell SBUButtonCell = new TableCell();
        SBUButtonCell.Controls.Add(SBUSaveButton);
        SBUButtonCell.ColumnSpan = 3;
        TableRow SBUFooter = GenerateRow(SBUButtonCell);
        SBUFooter.TableSection = TableRowSection.TableFooter;
        SBUTable.Rows.Add(SBUFooter);
    }
}

void ShowMessage(string message)
{
    OutputString.Text = "<div class=\"message\">" + message + "</div>";
}

ListItem GenerateItem(string input)
{
    ListItem output = new ListItem();
    output.Text = input;
    return output;
}

TableCell GenerateCell(string text)
{
    TableCell output = new TableCell();
    output.Text = text;
    return output;
}

TableRow GenerateRow(params TableCell[] cells)
{
    TableRow output = new TableRow();
    foreach (TableCell cell in cells)
        output.Cells.Add(cell);
    return output;
}

TableRow GenerateHeaderRow(params string[] columns)
{
    TableRow output = new TableRow();
    output.TableSection = TableRowSection.TableHeader;

    foreach (string column in columns)
    {
        TableCell thisCell = new TableCell();
        thisCell.Text = column;
        output.Cells.Add(thisCell);
    }

    return output;
}
  • 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-21T03:53:02+00:00Added an answer on May 21, 2026 at 3:53 am

    previousSBUClient and previousSBU will always be blank on each post back, so why do you compare against them on the Page_Load? If you want their values saved between postbacks you need to save them in ViewState, I suggest code like:

    public string PreviousSBU
    {
        get { return Convert.ToString(ViewState["PreviousSBU"] ?? string.Empty); }
        set { ViewState["PreviousSBU"] = value; }
    }
    

    Perhaps its because you add multiple header rows to the table, and only the contents between the first through the second get displayed? Any header rows after added don’t get displayed?

    On each postback you add a new header row. But the TextBox’s are created on each postback and not saved between, so you shouldn’t be seeing anything at all if thats the case.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into

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.