1

In ASP .NET code, I see lot of if(!IsPostBack) checks.

Let's take an example of ASP.NET MVC, when request is made to a controller method for the first time, it serves a view, say it is a razor page in this case. In this first request the IsPostBack will be false.

Once the view is served by the controller, is the same controller method called again automatically without any user interaction? And this time IsPostBack will be true?

Or the controller method is only called on some user interaction, say user submits a form or something similar, then controller action method is called and the IsPostBack flag is true?

growler
  • 23
  • 5
  • 2
    IsPostBack is a web forms concept: https://stackoverflow.com/questions/777179/asp-net-mvc-is-ispostback-still-here – Steve Greene Jan 09 '18 at 16:21
  • I do not know about ispost back but Post Back means when data(something that user has explicitly provides) has to be sent to the controller from the view.Like when submitting forms. – Sudeep Shrestha Jan 09 '18 at 16:24
  • This question is tagged MVC and webforms. Which is it? If it is both, you need to clarify the question. – Steve Greene Jan 09 '18 at 17:32
  • @SudeepShrestha - thanks, I'm new to web development. This is what I wanted to know as well. So PostBack is data being posted back to server by user or any other means. – growler Jan 10 '18 at 15:04
  • @SteveGreene - thanks for you comment. I wasn't sure if this applies to MVC or web forms. but looks like this is only web forms thing. – growler Jan 10 '18 at 15:04
  • What is confusing is you mention controllers - that is an MVC thing. Also, it is possible to mix the 2. Showing the code in question might help. – Steve Greene Jan 10 '18 at 16:05

1 Answers1

0

IsPostBack is used to check if it is the first request or a result of user interaction e.g. a button click to submit a form

E.g. When you first load the page, you can make a database call and store values in cache. If the user posts the page back, you can check IsPostBack and load values from cache instead, saving a heavy resource call

Aman B
  • 2,276
  • 1
  • 18
  • 26