ViewsState, DropDownList and WebControl

J

Jose Fernandez

Hello
First of all, excuse my english

We all know that in a normal page with codebehind we add a dropdownlist
control and we bind() it in the (!ISPOSTBACK), so, we don't need to go to
database again 'cause its value are saved (i assume viewstate).

Well. I have a class that inherits from WebControl and INamingContainer.
This class Load an ASCX control (that contains other controls in itself like
textbox and Dropdownlist). In the CreateChildControls i add the ascx and
initialize its inner controls (by FindControl method). So, i override the
DataBind() and if it's not postback, then i bind() the dropdownlist. this
works right, BUT if there is any postback, it doesn't load its
values(listItems) . The textbox keeps its value. I have been reading that
some people override LoadViewState and SaveViewState in order to persits
Attributes inside the listItems. Is there anything i can do to make my
dropdownlist persists its values so i don't have to load from database
everytime there is a postback?

Can anybody help me on this?
Thanks in advance


Ahora. mi problema es el siguiente. Tengo una clase que hereda de WebControl
y INamingContainer donde agrego aleatoriamente un ascx que quiera mostrar.
El problema es que despues que agrego el control ascx (en el
CreateChildControls) y le inicializo sus controles internos (como textbox,
dropdown, etc.).
hago un override del metodo DataBind y alli le paso el datasource que es un
arraylist que saco de una base de datos si NO ES POSTBACK. El tema es que
cuando hay un postback de nuevo en mi pagina, el textbox mantiene su valor
pero el dropdown me sale completamente vacio. Pierde sus valors. hay algo
que estoy haciendo mal? Se que haciendo overrides del LoadViewState y
SaveViewState se resuelve. Lo he leido. pero no he podido hacerlo funcionar.
Alguien tiene idea?
Ayuda Por Favor. estoy vuelto loco con esto.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top