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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:11:15+00:00 2026-05-16T00:11:15+00:00

I’m a PHP guy learning some .NET. I am tinkering around with the UpdatePanel

  • 0

I’m a PHP guy learning some .NET. I am tinkering around with the UpdatePanel control for a little dashboard.

In .aspx file, I’m using OnClick to trigger the code behind file to update the label by +1

<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div id="Container">
<asp:UpdatePanel runat="server" ID="UpdatePanel1" 
    OnLoad="UpdatePanel1_Load">
  <ContentTemplate>
      <asp:Label ID="CounterOne" runat="server" Text="Label"></asp:Label>
  </ContentTemplate>

</asp:UpdatePanel>

<asp:Button ID="Button1" runat="server" Text="Button" OnClick="UpdatePanel1_Increment"/>

However, when I run it on localhost. It increments the first time I push the button, but each subsequent click does nothing.

Here is the CodeBehind:

 public void UpdatePanel1_Increment(object sender, EventArgs e)
        {
            counter = counter + 1;
            CounterOne.Text = counter.ToString();

        }

Do I need to reset something on the control?

Thanks!

Note: I know there are more bandwidth friendly ways to do this, but I’m just testing out some ideas…

  • 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-16T00:11:16+00:00Added an answer on May 16, 2026 at 12:11 am

    Remove the OnLoad even from the UpdatePanel and add the following code before you close the UpdatePanel.

    <Triggers>
       <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" /> 
    </Triggers> 
    

    By adding the Trigger, you are telling the ScriptManager to update this UpdatePanel whenever Button1 is clicked.

    This link is a great introduction from http://www.asp.net on how to use UpdatePanels and Triggers: http://www.asp.net/ajax/tutorials/understanding-asp-net-ajax-updatepanel-triggers

    EDIT: Your problem is likely related to the counter variable in UpdatePanel1_Increment. Every time you postback, the counter variable is being reset to 0. So, the UpdatePanel is being updated correctly only it is being updated with 0 + 1 = 1 every time. UpdatePanels create the illusion of synchronous updates but the update is actually occurring asynchronously and the variables are not maintained by the server. You need some way to tell the code behind that the new value for counter has been updated since the counter value is “forgotten” immediately after you update the UpdatePanel.

    There are a lot of ways to pass the counter value to the server. A quick and easy way is as follows:

    public void UpdatePanel1_Increment(object sender, EventArgs e)
            {
                counter = int.Parse(CounterOne.Text); //This is how we'll tell the server what the counter value currently is.
                counter = counter + 1;
                CounterOne.Text = counter.ToString();
    
            }
    

    Finally, make sure that CounterOne.Text = “0” when the page loads and everything will work as you expect it to.

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

Sidebar

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.