Asp.net restores data after postback

Hi everyone, I have the following problem which is really driving me crazy.

After doing any postback, multiple controls won't regroup like

DetailsView with attached ObjectDataSource (ObjectContainerDataSource in my case) LoginView does not show LoggedInTemplate, but LoginStatus shows me that you are logged in.

I'm almost desperate and I like to know if you've had the same problem or something similar in the past and can give me some hint.

Thanks in advance

+1


a source to share


3 answers


If the binding is done in the Page_Load method, make sure it is inside an if not postback loop.

if (!IsPostBack)
    {
        //Your code to bind data
    }

      



After each postback, a page load event is fired. Therefore, if the controls are not bound inside the above loop, the binding will be executed every time a postback occurs.

+2


a source


Without seeing any of your actual code, I would suggest you look at the EnableViewState settings for the page and individual controls.

This is a good article on managing viewstate .

You should also look for the code in this section on page_page ()



if(!IsPostback)
{
    // code to bind some of your controls
} 

      

This code will only be called the first time the page is entered, not on postbacks. If you leave the page and return, then the anchor code will run again.

+1


a source


Is your data binding on the page_load event? If not, do you overwrite when the page reloads?

Are your controls loaded dynamically?

0


a source







All Articles