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