Custom Controls Variables persistence.

N

Nadav

I am building custom controls with <asp: tags and
instance variables.

The <asp: tags persist between post backs but the
instance variables do not. How do I get around this?

Thanks in advance.
 
A

Alessandro Zifiglio

hi Nadav,
add the declaration PersistenceMode(PersistenceMode.InnerProperty) over your property. This Specifies how an ASP.NET server control property or event is persisted declaratively in an .aspx or .ascx file.
*Note that : PersistenceMode(PersistenceMode.InnerProperty) Specifies that the property persists in the ASP.NET server control as a nested tag. This is commonly used for complex objects; those that have persistable properties of their own
Look in the docs for more info, search under "PersistenceMode Enumeration"
As an alternative you can Specifiy how a property on a component is saved by a designer using DesignerSerializationVisibilityAttribute Class, it all depends on what you want to do and how you want to persist the data.

If you want it to go into the
 
A

Alessandro Zifiglio

wait, think i misread your post, what do you mean by instance variables ? ;P
hi Nadav,
add the declaration PersistenceMode(PersistenceMode.InnerProperty) over your property. This Specifies how an ASP.NET server control property or event is persisted declaratively in an .aspx or .ascx file.
*Note that : PersistenceMode(PersistenceMode.InnerProperty) Specifies that the property persists in the ASP.NET server control as a nested tag. This is commonly used for complex objects; those that have persistable properties of their own
Look in the docs for more info, search under "PersistenceMode Enumeration"
As an alternative you can Specifiy how a property on a component is saved by a designer using DesignerSerializationVisibilityAttribute Class, it all depends on what you want to do and how you want to persist the data.

If you want it to go into the
 
J

Jeffrey Tan[MSFT]

Hi Nadav,

Thanks for posting in this group.
Based on my understanding, you are building a custom control which has many
"customized" member variables associated it. But when postback, you find
these member variables' did not keep it original value(The value that being
set in first load time)
Actually, in asp.net web form mechanism, a control's life time is very
short on server side. Because of Http protocol's stateless, asp.net persist
the control's state through ViewState. Asp.net will persist the pre-defined
fields of control in ViewState, while for the persistence of customized
variables, you should persist them in viewstate yourself.

For more information about state management, please refer to the articles
below:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconmantainingstateincontrol.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vbconchoosingserverstateoption.asp

Hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top