Reputation: 1832
I have a composite control that has a DropDownList inside.
The problem i have is the next one: When i load the data on the Page_Load (the first time the page is loaded) everything works fine, but when there is a postback and i want to refresh the datasource (i mean, with a different one), the datasource is saved to the ViewState, but not databinded to the dropdownlist.
I found out that this is happening because the page lifecycle changes from the first time it is rendered to the second time:
So my problem is that the i do the databind in the CreateChildControls() but the datasource is setted on the Function_Called_On_Postback(), so, the dropdownlist doesn't get the changes.
Do you know how can i fix this? Do you have at least an advice?
Thanks a lot!
Upvotes: 2
Views: 168
Reputation: 708
I'm assuming that the post back is being caused by some event on the page such as a selected index changed on our DDL or a click event from a button. If that is the case, then you should be able to set the data source of the DDL in the event handler method of the event in question.
For this to work correctly, you will have to load the data for DDL in the Page_Load method on the initial load not on post backs. This can be checked with Page.IsPostBack.
if(!Page.IsPostBack) { /* initial load data binding of the DDL */ }
Upvotes: 0