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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:44:57+00:00 2026-05-19T03:44:57+00:00

I have an application that I am currently writing that works by iterating through

  • 0

I have an application that I am currently writing that works by iterating through nodes, and then updating the page with the information of the current node. I have an UpdatePanel in the page which contains a label, textbox, and a button. The label lists the currently available children of the current node, the user enters in which child they want to go to into the textbox, and then hits the submit button. I set the new value of the node in the submit button’s event handler.

Here’s my problem: Every time I enter in which node I want to navigate to, the object resets its value to the value it was initially initialized to. I have even put this same code into a Windows Form to validate that it’s working correctly to iterate through my tree, and it works as it should, so I know my problem is AJAX-related.

This is the first app that I have written using AJAX, so I am still in the process of learning how it works. Any help would be greatly appreciated. I have Googled and searched SO through and through.

Here is the HTML:

<form id="form1" runat="server">    
    <asp:ScriptManager ID="ScriptManager" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:Label ID="question" runat="server" Text=""></asp:Label>
            <br />
            <asp:TextBox ID="answer" runat="server"></asp:TextBox>
            <br />
            <asp:Button ID="Submit" runat="server" Text="Submit" onclick="Submit_Click" />
        </ContentTemplate>
    </asp:UpdatePanel>
</form>

And the C#:

    protected void Submit_Click(object sender, EventArgs e)
    {
        int ans = int.Parse(answer.Text);

        if (!current.ChildIDs.Contains(ans))
        {
            return;
        }
        current = tree.Node(ans);
        question.Text = current.Question;
    }

current is the current node, which has a public ArrayList of all of its children’s IDs. tree is the NodeTree I have; calling Node just returns the new node. Both current and Tree get initialized in the Page_Load event, and that only fires once (when the page is first loaded).

It’s really pretty simply code; I’m just having difficulty understanding why the AJAX isn’t working correctly.

  • 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-19T03:44:58+00:00Added an answer on May 19, 2026 at 3:44 am

    I have even put this same code into a
    Windows Form to validate that it’s
    working correctly to iterate through
    my tree, and it works as it should, so
    I know my problem is AJAX-related.

    It sounds like you’re expecting ASP.NET to remember what the object current is between requests, since that’s how Windows forms applications work.

    Web applications are stateless – after each request, ASP.NET discards all your variables. To access the variable during a subsequent request, you have to either:

    1) Send enough data with the request to reconstruct the variable. You can do this using a querystring parameter or an HTML form value (the hidden fields another response mentioned).

    2) Save the variables in a Session store (which can be in-memory or backed by a database).

    3) Store the value in a coookie.

    Of these three, it’s easiest to show you how to use Session, given what you’ve shared in your question. However, beware: session has its risks – by default, ASP.NET session objects are stored in-memory, and it’s a potential security hazard. But here’s how you should be able to get your application to work.

    // In your Page_Load code that initializes your 'current' variable
    
    // When the user first requests the page, create a new Node
    if (! this.IsPostBack) 
    {
        Node current = new Node(); //
        Session("currentNode") = current;
    } 
    // When the user clicks a button on the page (posts), use the
    // node in session instead
    else 
    {
        current = Session("currentNode");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that I am currently writing that will use Spring and
I'm currently writing an application that works with modules. The module part is all
I have an application that is currently running against a 32-bit SQL Server 2005
I have a web application that currently sends emails. At the time my web
I have a web application that's branded according to the user that's currently logged
I currently have an application that gets hit with over 20,000 users daily and
Currently I have an application that receives an uploaded file from my web application.
I have a Windows GUI application that's using the Qt framework (currently version 3.3.5,
I currently have an MS Access application that connects to a PostgreSQL database via
We currently have a quite complex business application that contains a huge lot of

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.