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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:58:54+00:00 2026-06-11T08:58:54+00:00

When clicking the button for first time change button text, on 2nd click redirects

  • 0

When clicking the button for first time change button text, on 2nd click redirects to other page –

public partial class _Default : System.Web.UI.Page
{
    int clickCount;
    protected void btn_clicked(object sender, EventArgs e)
    {
        clickCount++;
        if (clickCount == 1)
            (sender as Button).Text = "go to landing page";
        else
            Response.Redirect("LandingPage.aspx");
    }
}

As obvious every time page reloads clickCount will be re-initialized and else block is never going to execute.
To maintain the clickCount state I may use view state, session state, application state, hidden field or JS code may be etc. What is best for this particular case -> Ques 1.

As MVC is stateless and similar code written in controller as well, will re-initlialize clickCount every time ActionHandler or controller is instantiated. How do you handle similar situation in ASP.NET MVC -> Ques. 2

  • 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-11T08:58:56+00:00Added an answer on June 11, 2026 at 8:58 am

    Create a model to pass into the view with the property on it:

    public int ClickCount{get;set;}
    

    Then in the view, create a hidden value

    @Html.HiddenFor(f=>f.ClickCount)
    

    During the post event on the controller, update the model

    public ActionResult(ViewModel model){
    model.ClickCount++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When loading a page for the first time (!IsPostback), I am creating a button
I have an updatepanel which after clicking one button is submitting the page. The
im having a gridview in only page and on clicking a button column field
logging into django admin fails when 'log in' button is pressed first time, but
i have a button and for the first time it is not toggling when
I want a text-input change event to disable edits to other (rather complex)fields in
I use watir for testing in RadRails IDE.After clicking button Delete appears window Message
On clicking a button, I want the selected rows to be inverted (non-selected rows
Iam in parent view while clicking the button in the parent view I want
I need to call a function by clicking a button. The button is on

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.