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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:30:58+00:00 2026-06-02T03:30:58+00:00

In my web application I have two, a ViewState and a Session which hold

  • 0

In my web application I have two, a ViewState and a Session which hold values, the problem is that I need to reset one and leave the other as it is through a click of a button. If I use Response.Redirect in my button, both the ViewState and the Session are resetted. I tried using if(!IsPostBack) but I don’t think this would work in a button event. I would really appreciate your suggestions and help.

CODE:

// There is a ViewState above this code which I have to reset

   protected void Button_Click(object sender, EventArgs e)
   {
       Session["Counter"] = (int)Session["Counter"] + 1; // I do not want to reset this Session.
       Label1.Text = Session["Counter"].ToString();
       Response.Redirect("Page1.aspx"); // If this button is pressed then Session["counter"] is resetted which I don't want to happen


}

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-02T03:30:59+00:00Added an answer on June 2, 2026 at 3:30 am

    If you simply want to incremement the counter, all you need to do is this:

     public override void OnLoad(EventArgs e)
     {
         if(!Page.IsPostBack)
         {
            if (Session["PersistedCounter"] == null)
                Session["PersistedCounter"] = "0";
    
            Label1.Text = Session["PersistedCounter"];
         }
     }
    
     protected void Button_Click(object sender, EventArgs e)
     {
         int oldValue = int.Parse(Label1.Text);
         Label1.Text = (oldValue + 1).ToString();
         Session["PersistedCounter"] = Label1.Text;
     }
    

    Since the page already saves state, the label will post back to the server with it’s current value restored from view state. You simply pull the value, and then set the value with your modifications. Try that, and it should work.

    Your solution is actually overcomplicating things.

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

Sidebar

Related Questions

We have two applications running on single machine,one of which is web application that
Suppose you have two seperate ASP.NET Web Application projects that both need to use
i'm need to develop and web application that uses maps, and i have two
I have two web application projects which are related. One is the website itself
I have a web application and two class files, First class is MyClass.class which
I have a web application that uses two databases. DB1 Users perform their CRUD
I have two web application hosted on different server.For eg. one is main application
I have two folders in my asp.net web application in which I create new
Basically I have two applications: a PHP web application that runs over Apache and
I have an ASP.NET web application that uses jQuery on client side. On one

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.