Dropdownlist calls page load

Asked

Viewed 224 times

0

I have a dropdownlist that takes data from the bank sql server. I carry that dropdownlist in page_load within a if(!IsPostBack){} and from what I understand of !IsPostBack, it only goes there if it’s the first time it loads the page.

What bothers me is that every time I click on one of the items from dropdownlist, page reload. Placing a breakpoint on page_load from the page, I saw that goes there every time I click on an item.

Why does this happen?
How to make it not reload the page for each chosen item?

2 answers

1

I had only entered the code snippet if(IsPostBack == false) the moment the page is loaded the first time on the server because no Post by the client.

In your case when you clicked on an option of dropdownlist, automatically made a request(a Post) to the server, with that the page updated, but did not enter the clause if(IsPostBack == false) for it is a Postback.

The AutoPostBack = "true" is usually used to get some kind of validation during the selection of the item, the ideal is to use an updatepanel (only a section of the page is updated through an ajax call) not to get the feeling that the page has been updated.

If in your case, there is no such need the best alternative is to leave the AutoPostBack = "false".

0

I identified what made him do it, there was an Autopostback = "true" on the dropdownlist. I will search for it, but in a simple way, I can say that the page sent data to the server and then returned to the browser because of this Autopostback.

  • use Autopostback = "true" in the dropdownlist in the form if you need to load another field or another dropdownlist that depends on the value chosen in the first, so your second field will be loaded.

Browser other questions tagged

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