473,804 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Property. Control or View State?

Hello,

I am creating a control which I will compile in a class.
I am having problems when I use a property in the View State:

' Items
<Bindable(True) , Category("Data" ), DefaultValue("" ),
Localizable(Tru e)_
Property Items() As Generic.List(Of String)
Get
If ViewState("Item s") Is Nothing Then
Return New Generic.List(Of String)
Else
Return ViewState("Item s")
End If
End Get
Set(ByVal Value As Generic.List(Of String))
ViewState("Item s") = Value
End Set
End Property ' Items

But I don't get problems if I use it in Control State:

Private _Items As New Generic.List(Of String)
Public Property Items() As Generic.List(Of String)
Get
Return _Items
End Get
Set(ByVal value As Generic.List(Of String))
_Items = value
End Set
End Property ' Items

Anyway, this is a little bit confusing to me.
Could someone tell me which one should I use?
I am working on ASP.NET 2.0.

Thanks,
Miguel

May 30 '07 #1
1 1609

shapper wrote:
Hello,

I am creating a control which I will compile in a class.
I am having problems when I use a property in the View State:

' Items
<Bindable(True) , Category("Data" ), DefaultValue("" ),
Localizable(Tru e)_
Property Items() As Generic.List(Of String)
Get
If ViewState("Item s") Is Nothing Then
Return New Generic.List(Of String)
Else
Return ViewState("Item s")
End If
End Get
Set(ByVal Value As Generic.List(Of String))
ViewState("Item s") = Value
End Set
End Property ' Items
I guess all the problems are caused by continuous creation of a new
List object
every time you ask for Items property. Try this:

Property Items() As Generic.List(Of String)
Get
If ViewState("Item s") Is Nothing Then ViewState("Item s") = New
Generic.List(Of String)
Return ViewState("Item s")
End Get
Set(ByVal Value As Generic.List(Of String))
ViewState("Item s") = Value
End Set
End Property

Regards, Mykola
http://marss.co.ua

May 30 '07 #2

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

Similar topics

3
3570
by: Kent Eilers | last post by:
I want to follow naming conventions for my controls - i usually prefix combo boxes with "cbo". When a form is in datasheet view however i do not want the user to see the 'cbo' prefix in front of the field name. Is there a way to retain this nomenclature and yet have the view display the field name (or anyname i want for that matter)? Thanks --
2
1904
by: SSW | last post by:
Hi: In aspx.cs page i had written the code below. I have a button control and only create TextBox Control dynamically. LoadViewState is Never called. But when we put datagrid/DataList it works. Can any one help me with this? Thanks, SSW
4
1582
by: Pham Nguyen | last post by:
I have two maybe related questions about view state and the life cycle of controls: 1) When does the view state in a control get restored? I thought there was a LoadViewState event that occured before the Load event when the view state got restored. However, I have a custom control that dynamically adds a Label control inside of its OnLoad() method. The Label still maintains its state across requests -- if the Label is added in the...
1
7591
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a dropdown in UC1 _________________________ 1) MainPage_Load 2) User Control_1 Load
5
9168
by: Leo J. Hart IV | last post by:
Hello, I'm hoping someone can help me out. I was wondering if the Enabled property of a CheckBox or RadioButton server control is stored in the ViewState. If not, is there some way to to add this property to ViewState? If needed, I can give you more info on exactly what I'm trying to do. Thanks,
0
5570
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control is used to view the state of the running jobs and schedule new jobs. The control also runs in the context of Internet Explorer (we do this so the administrators of the jobs can always receive the latest control). The property grid is used to...
0
1344
by: Rene Aichinger | last post by:
Hi, I've created a server control (it inherits from WebControl) wich has a property of genertic collection type. The type of the generic collection is NavigationItem, a little class I've created... The declaration of the collection property is that:
7
2596
by: David Lozzi | last post by:
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??? ...
2
2067
by: Chris | last post by:
I have created a date picker user control. I want to have a boolean property, which I can set to determine whether the control defaults to today's date. I have created a property which I set to true but when I create the child controls it has always reset to false. I know it has been set to true as I have trace written the value in the property "setter". Is the create child controls event the wrong place to set the textbox, with the date....
0
9595
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10097
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9175
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5535
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3835
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.