DropDownList calls the page load

0

I have a dropdownlist that takes data from the sql server database. I load this dropdownlist into the page_load within a if(!IsPostBack){} and from what I noticed from !IsPostBack , it only goes in there if it is the first time it loads the page. p>

What bothers me is that every time I click on one of the dropdownlist items, the page reloads. Placing a breakpoint in the page_load of the page, I saw it go there every time I click on an item.

Why does this happen? How do you prevent it from reloading the page for each chosen item?

    
asked by anonymous 22.10.2015 / 23:15

2 answers

1

You will only enter the if(IsPostBack == false) code snippet when the page loads the first time on the server because a Post was not run by the client.

In your case, when you clicked on a dropDownList option, it would automatically make a request (a Post ) to the server, so the page updated but did not enter the clause if(IsPostBack == false) because it is a PostBack .

AutoPostBack = "true" is usually used to get some type of validation during item selection, ideally to use an updatepanel (only a portion of the page is refreshed through an ajax call) so you do not have the feeling that page has been updated.

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

    
29.12.2015 / 15:31
0

I identified what made it do this, there was an AutoPostBack="true" in the dropDownList. I will search about 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.

    
23.10.2015 / 00:09