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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:03:48+00:00 2026-05-29T20:03:48+00:00

This following code handle button click event. When the user click first time it

  • 0

This following code handle button click event. When the user click first time it sets the lable as “First Time”, and when the user click second time it sets the lable as “Second Time”. But it doesn’t work properly. When I first click it, it sets the lable as “First time”, which is correct, but when I click second time, nothing happend.

My code:

int counter=0;    
protected void btnCompTagUpdate_Click(object sender, EventArgs e)
{

    if (counter == 0)
    {
        lable1.Text="First Time";
        counter++;
    }
    else if (counter == 1)
    {
        lable1.Text="Second Time";
        counter--;
    }

    }

How can I fix it?

  • 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-29T20:03:51+00:00Added an answer on May 29, 2026 at 8:03 pm

    The values of instance fields like counter are not saved across postbacks. You need to store counter in ViewState, Session, or some other persistent store, whichever is more appropriate. For example:

    private int Counter
    {
        get { return ((int?)this.ViewState["Counter"]).GetValueOrDefault(); }
        set { this.ViewState["Counter"] = value; }
    }
    

    Then reference this.Counter instead of counter in btnCompTagUpdate_Click.

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

Sidebar

Related Questions

An event handler can be removed with the following code in the button click
I have a button click event handler with the following pseudo code: private void
The following code doesn't work! 'this' in in the context when i access it
In the following code (inspired by this snippet), I use a single event handler
I have the following code: $(document).ready(function({ $(.click).click(function(){ alert(' The Button Was Clicked !'); });
I a WPF application I have the following event-handler of a button-click in a
I am haveing problems getting the command event args following the second click using
This following code gets this compile error: " invalid types 'int[int]' for array subscript
Did I not get enough sleep or what? This following code var frame=document.getElementById(viewer); frame.width=100;
I need help on this following aspx code aspx Code: <asp:Label ID =lblName runat

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.