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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:51:52+00:00 2026-06-02T09:51:52+00:00

I have a textbox that the user suppose to place numbers on it, and

  • 0

I have a textbox that the user suppose to place numbers on it,
and after he push the button, the number should pass to an array.

and each number and button pushed, should be saved in this array in order (for example : 3 , 4, 5, ….)

The problem is, that each time I push the button, then page_load occurs. I have this code :

    protected string[] CurrentArr;

    protected void Page_Load(object sender, EventArgs e)
    {

        if (CurrentArr != null)
        {
            CurrentArr = (string[])Session["CurrentArr"];      
        }
        else
            CurrentArr = new string[length];

which CurrentArr is the array that change over time.

I tried to solved it with AJAX as well :

<asp:ScriptManager runat="server" ID="sm">
    </asp:ScriptManager>

    <asp:UpdatePanel runat="server" ID="update">
        <ContentTemplate>
        <input type="text" class="response" id="how_many" name="guess" placeholder="Enter your guess..." />
        <asp:Button runat="server" class="button red" id="generate" name="generate" value="Generate!" OnClick="guess_Click" />
        <asp:Button runat="server" class="button red" id="win" name="win" value="you won"   />
        </ContentTemplate>
    </asp:UpdatePanel>

but it has no effect over my array (although my page doesnt post back…)

anyone has a solution ?

Thanks!

  • 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-06-02T09:51:55+00:00Added an answer on June 2, 2026 at 9:51 am

    You are using an UpdatePanel, it is inherently AJAXified. Just add a trigger section to catch the button click:

    <asp:UpdatePanel runat="server" ID="update">
        <ContentTemplate>
            <input type="text" class="response" id="how_many" name="guess" placeholder="Enter your guess..." />
            <asp:Button runat="server" class="button red" id="generate" name="generate" value="Generate!" OnClick="guess_Click" />
            <asp:Button runat="server" class="button red" id="win" name="win" value="you won"   />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="generate" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>
    

    The problem that you’re probably running into is that your array isn’t persisting through the postbacks. Try what you and ed were getting at, getting and setting from the session. I prefer not to use old school arrays. Consider a list, they are more versatile. And if you specifically need an array at the end then just use myList.ToArray();

    private List<int> CurrentArr = new List<string>();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if(Session["CurrentArr"] != null)
        {
            //if there is something stored in the session variable then grab that as a working array
            CurrentArr = (List<string>)Session["CurrentArr"];
        }
        else
        {
            //if not, then initialize one
            CurrentArr = new List<string>();
            Session["CurrentArr"] = CurrentArr;
        }
    }
    
    protected void guess_Click(object sender, EventArgs e)
    {
        //get reference to the button clicked like you said in your question
        var btnMyButton = sender as Button; 
        btnMyButton.Enabled = false; //example of using the reference, disable the button that was clicked
    
        //add the value of your text box to the array/list, sort, then update the session
        this.CurrentArr.Add(txtYourTextBox.Text);
        this.CurrentArr.Sort();
        Session["CurrentArr"] = this.CurrentArr;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a textbox and I want that when the user types inside
Hi I have a textbox that takes a username input. When the user submits
I have a TextBox in a Windows Form that allows a user to enter
I have a composite drop down calendar user control that consists of a textbox
I have a textbox that I would like for only numbers. But if I
I have a textBox control that lets the user their email address/addresses. The use
I have a textbox.In that I have to allow the user to type some
suppose I have a boolean function in my ValidationClass that checks user input for
In my app, I have a textbox that the user can fill. Most times,
I have an ASP.Net web user control that contains a TextBox and a calendar

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.