User Controls not keeping property values

D

David Lozzi

Howdy,

I have a usercontrol in my aspx page and when the page loads, I send it some
property values based on the data displayed. I am sending it to a public
property like below. However the usercontrol has some functions and when the
function is run, I lose all of the property values. If I assign the property
value to a text box, the information is not lost in the text box. I think
this is by design, but how do I get around it???

Public Property Height() As Integer
Get

Return _height

End Get

Set(ByVal Value As Integer)

_height = Value

End Set

End Property

Here is the property saving to a text box which works well.

Public Property FileName() As String

Get

Return txtRegForm.Text

End Get

Set(ByVal Value As String)

txtRegForm.Text = Value

End Set

End Property


I don't want to make a text box for each property, that can get messy.

Thanks!!
 
B

Ben Dewey

Is your user control inside a databound control? a repeater or a datagrid?

If so what kind? and when/how are you setting the UserControl data?
 
S

Steven Cheng[MSFT]

Hi David,

I think Christopher's consideration are reasonable. ASP.NET web pages are
request/response based, and all the in-memory page variables are not
persisted between mulitple page requests(postback....). So if we want some
certain member varriables to be persisted and shared between postbacks, we
need to store them into some persistent storage, such as SessionState or
Viewstate....

e.g:
===============
Public Property Height() As Integer
Get

Return ViewState("__HEIGHT")

End Get

Set(ByVal Value As Integer)

ViewState("__HEIGHT") = value

End Set

End Property
=================

Also, you can add some additional code to do bad value protection in the
property accessor....

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)






--------------------
| From: "David Lozzi" <[email protected]>
| References: <[email protected]>
<#[email protected]>
| Subject: Re: User Controls not keeping property values
| Date: Mon, 19 Dec 2005 18:48:40 -0500
| Lines: 18
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-RFC2646: Format=Flowed; Response
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: c-24-63-42-200.hsd1.ma.comcast.net 24.63.42.200
| Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTFEED02.phx.gbl!tornado.fa
stwebnet.it!tiscali!newsfeed1.ip.tiscali.net!news.glorb.com!newsfeed.hal-mli
net!feeder1.hal-mli.net!news.alt.net!msrtrans!TK2MSFTNGP08.phx.gbl!TK2MSFTN
GP09.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:365834
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| It is not, its just part of a form.
|
| --
| David Lozzi
| Web Applications Developer
| dlozzi@(remove-this)delphi-ts.com
|
|
|
| | > Is your user control inside a databound control? a repeater or a
| > datagrid?
| >
| > If so what kind? and when/how are you setting the UserControl data?
| >
|
|
|
 
D

David Lozzi

That works great. Any precautions I should be aware of when using the
ViewState? Does it empty itself?

Thanks,
 
S

Steven Cheng[MSFT]

Thanks for your quick response David,

As for ViewState, you may need to read some other reference so as to better
understand it's mechanism and how it working with the asp.net page's
lifecycle. here are some useful reference on asp.net viewstate and
webcontrol state management:

#Understanding ASP.NET View State
http://msdn.microsoft.com/library/en-us/dnaspp/html/viewstate.asp?frame=true

#ASP.NET State Management
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconaspstatemanagement
..asp?frame=true

#Creating Custom Web Controls with ASP.NET 2.0
http://msdn.microsoft.com/library/en-us/dnvs05/html/custwebcon.asp?frame=tru
e

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)









--------------------
| From: "David Lozzi" <[email protected]>
| References: <[email protected]>
<#[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: User Controls not keeping property values
| Date: Tue, 20 Dec 2005 01:14:56 -0500
| Lines: 104
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: c-24-63-42-200.hsd1.ma.comcast.net 24.63.42.200
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:365865
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| That works great. Any precautions I should be aware of when using the
| ViewState? Does it empty itself?
|
| Thanks,
|
| --
| David Lozzi
| Web Applications Developer
| dlozzi@(remove-this)delphi-ts.com
|
|
|
| | > Hi David,
| >
| > I think Christopher's consideration are reasonable. ASP.NET web pages
are
| > request/response based, and all the in-memory page variables are not
| > persisted between mulitple page requests(postback....). So if we want
some
| > certain member varriables to be persisted and shared between postbacks,
we
| > need to store them into some persistent storage, such as SessionState or
| > Viewstate....
| >
| > e.g:
| > ===============
| > Public Property Height() As Integer
| > Get
| >
| > Return ViewState("__HEIGHT")
| >
| > End Get
| >
| > Set(ByVal Value As Integer)
| >
| > ViewState("__HEIGHT") = value
| >
| > End Set
| >
| > End Property
| > =================
| >
| > Also, you can add some additional code to do bad value protection in the
| > property accessor....
| >
| > Hope helps. Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| >
| >
| >
| > --------------------
| > | From: "David Lozzi" <[email protected]>
| > | References: <[email protected]>
| > <#[email protected]>
| > | Subject: Re: User Controls not keeping property values
| > | Date: Mon, 19 Dec 2005 18:48:40 -0500
| > | Lines: 18
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | X-RFC2646: Format=Flowed; Response
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | Message-ID: <[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: c-24-63-42-200.hsd1.ma.comcast.net 24.63.42.200
| > | Path:
| >
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTFEED02.phx.gbl!tornado.fa
| >
stwebnet.it!tiscali!newsfeed1.ip.tiscali.net!news.glorb.com!newsfeed.hal-mli
| >
net!feeder1.hal-mli.net!news.alt.net!msrtrans!TK2MSFTNGP08.phx.gbl!TK2MSFTN
| > GP09.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:365834
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | It is not, its just part of a form.
| > |
| > | --
| > | David Lozzi
| > | Web Applications Developer
| > | dlozzi@(remove-this)delphi-ts.com
| > |
| > |
| > |
| > | | > | > Is your user control inside a databound control? a repeater or a
| > | > datagrid?
| > | >
| > | > If so what kind? and when/how are you setting the UserControl data?
| > | >
| > |
| > |
| > |
| >
|
|
|
 
D

David Lozzi

Thanks

--
David Lozzi
Web Applications Developer
dlozzi@(remove-this)delphi-ts.com
 

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

Similar Threads

Property 1
Property 0
Property 1
Control Property. 3
Setting the value of a Master page's control's property using a property of the Master page 25
Property 1
Property. 3
TextBox and Property 1

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top