Functionality of ! Ispostback

Asked

Viewed 485 times

1

What is the real usefulness of this if(!Ispostback) of the page_load of the aspx pages?

protected void Page_Load(object sender, EventArgs e)
{
 if(!IsPostBack)
 {
  //codigo
 }
}

2 answers

1


This condition is for the content within this if only to be executed the first time the Page is loaded, because in ASPX every time you interact with the page it makes the Postback.

  • what types of interaction?

  • 1

    @Pedrobelino For example click on a button that does a post for the server, for example: a form, the reference I used was this thread here at MSDN

  • 1

    Every time you interact on the page you need a server response like submitting a form generates a postback.

1

In . net Webforms there are 2 flags indicating how the request was made for your page. They are: IsPostBack and IsCallback.

These two flags are used to implement logic for your code, through the type of request that you are receiving.

Here’s an example of how you can identify your requests:

!IsPostBack & !IsCallback: Indicates that your request was made through the verb HTTP GET and possibly it’s the first time she’s been carried.

!IsPostBack & !IsCallback: Indicates that your request was made through the verb HTTP POST and probably not the first time your page is being loaded.

!IsPostBack & IsCallback: Indicates that your request was triggered by an event CallBack implemented on your page.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.