473,387 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

User Controls not keeping property values

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!!

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


Dec 19 '05 #1
7 2578
Look at using either Session or ViewState variables.
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

"David Lozzi" <Da********@nospam.nospam> wrote in message
news:Oa**************@TK2MSFTNGP09.phx.gbl...
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!!

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

Dec 19 '05 #2
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?
Dec 19 '05 #3
It is not, its just part of a form.

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

"Ben Dewey" <As*********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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?

Dec 20 '05 #4
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" <Da********@nospam.nospam>
| References: <Oa**************@TK2MSFTNGP09.phx.gbl>
<#d**************@TK2MSFTNGP15.phx.gbl>
| 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: <eT**************@TK2MSFTNGP09.phx.gbl>
| 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!TK2MSF TFEED02.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
|
|
|
| "Ben Dewey" <As*********@hotmail.com> wrote in message
| news:%2****************@TK2MSFTNGP15.phx.gbl...
| > 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?
| >
|
|
|

Dec 20 '05 #5
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

"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:IR**************@TK2MSFTNGXA02.phx.gbl...
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" <Da********@nospam.nospam>
| References: <Oa**************@TK2MSFTNGP09.phx.gbl>
<#d**************@TK2MSFTNGP15.phx.gbl>
| 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: <eT**************@TK2MSFTNGP09.phx.gbl>
| 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!TK2MSF TFEED02.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
|
|
|
| "Ben Dewey" <As*********@hotmail.com> wrote in message
| news:%2****************@TK2MSFTNGP15.phx.gbl...
| > 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?
| >
|
|
|

Dec 20 '05 #6
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...asp?frame=true

#ASP.NET State Management
http://msdn.microsoft.com/library/en...tatemanagement
..asp?frame=true

#Creating Custom Web Controls with ASP.NET 2.0
http://msdn.microsoft.com/library/en....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" <Da********@nospam.nospam>
| References: <Oa**************@TK2MSFTNGP09.phx.gbl>
<#d**************@TK2MSFTNGP15.phx.gbl>
<eT**************@TK2MSFTNGP09.phx.gbl>
<IR**************@TK2MSFTNGXA02.phx.gbl>
| 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: <OP**************@TK2MSFTNGP11.phx.gbl>
| 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!TK2MSFT NGP11.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
|
|
|
| "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| news:IR**************@TK2MSFTNGXA02.phx.gbl...
| > 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" <Da********@nospam.nospam>
| > | References: <Oa**************@TK2MSFTNGP09.phx.gbl>
| > <#d**************@TK2MSFTNGP15.phx.gbl>
| > | 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: <eT**************@TK2MSFTNGP09.phx.gbl>
| > | 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!TK2MSF TFEED02.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
| > |
| > |
| > |
| > | "Ben Dewey" <As*********@hotmail.com> wrote in message
| > | news:%2****************@TK2MSFTNGP15.phx.gbl...
| > | > 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?
| > | >
| > |
| > |
| > |
| >
|
|
|

Dec 20 '05 #7
Thanks

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

"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:5r**************@TK2MSFTNGXA02.phx.gbl...
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...asp?frame=true

#ASP.NET State Management
http://msdn.microsoft.com/library/en...tatemanagement
asp?frame=true

#Creating Custom Web Controls with ASP.NET 2.0
http://msdn.microsoft.com/library/en....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" <Da********@nospam.nospam>
| References: <Oa**************@TK2MSFTNGP09.phx.gbl>
<#d**************@TK2MSFTNGP15.phx.gbl>
<eT**************@TK2MSFTNGP09.phx.gbl>
<IR**************@TK2MSFTNGXA02.phx.gbl>
| 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: <OP**************@TK2MSFTNGP11.phx.gbl>
| 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!TK2MSFT NGP11.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
|
|
|
| "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| news:IR**************@TK2MSFTNGXA02.phx.gbl...
| > 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" <Da********@nospam.nospam>
| > | References: <Oa**************@TK2MSFTNGP09.phx.gbl>
| > <#d**************@TK2MSFTNGP15.phx.gbl>
| > | 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: <eT**************@TK2MSFTNGP09.phx.gbl>
| > | 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!TK2MSF TFEED02.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
| > |
| > |
| > |
| > | "Ben Dewey" <As*********@hotmail.com> wrote in message
| > | news:%2****************@TK2MSFTNGP15.phx.gbl...
| > | > 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?
| > | >
| > |
| > |
| > |
| >
|
|
|

Dec 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Andrea Williams | last post by:
I'm trying to set up a user control and change some values from the aspx page, but I keep running into trouble. What I really would like to do is be able to set a Label.Text in the user control...
1
by: Robert Howells | last post by:
Perhaps I'm just too new at this to pull it off, or perhaps it's just bad architecture. I'd appreciate some feedback on the the wisdom (or lack thereof) in attempting the following: I'm not new...
3
by: Kezza | last post by:
Hi There.. I have dynamically created some textbox and checkbox controls by adding them to a panel. Now I would like to get the values out. I have created a for each loop that I can see the...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
6
by: Louise | last post by:
I use Visual Basic .NET Framework 1.1, Visual Studio. I have a Web page (aspx) referencing a control (ascx) that has a placeholder that is assigned one of 2 child controls through buttons. The...
8
by: MattB | last post by:
I have a asp.net 1.1/vb application that has a page with a bunch of dynamically added User Controls. When I add the controls, I set the UserControl.EnableViewState to true. For all my controls...
2
by: | last post by:
I want to use codebehind to pass property values to a control that I've embedded INSIDE of a user control. In other words, let's say I have the following: MyPage.aspx ....with the following...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
2
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.