Trying to create a collectin of objects

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I'm tyring to create a collection of an object inside an object I have tried to use the code written in the following URL
http://msdn.microsoft.com/library/d...n/html/vaconcreatingyourowncollectionclass.as
its working fine when I test it from VB.net but my application is a web-application , I tried to use the same classes that I have created and tested in VB.Net the collection counter is always set to 1 even If I add 3 or 7 objects, I don't know why this is happing the same classes are working in VB Form, Any body know whats the problem ?
 
Can you post some code from you web form? Have you remembered that web forms
are stateless?

Nick Holmes.

hanaa said:
Hi,
I'm tyring to create a collection of an object inside an object I have
tried to use the code written in the following URL:
http://msdn.microsoft.com/library/d.../html/vaconcreatingyourowncollectionclass.asp
its working fine when I test it from VB.net but my application is a
web-application , I tried to use the same classes that I have created and
tested in VB.Net the collection counter is always set to 1 even If I add 3
or 7 objects, I don't know why this is happing the same classes are working
in VB Form, Any body know whats the problem ?
 
I'm new to Asp.net Could you expalin to me what do you mean by web forms are stateless
The Following Code is the part written fro the Add button it is the same as the one in the previous menthioned URL

Dim mywidgetCol As New widgetCollection

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Clic
Dim awidg As New Widge
awidg.name = TextBox1.Tex
mywidgetCol.Add(awidg
awidg.name = TextBox4.Tex
mywidgetCol.Add(awidg
TextBox2.Text = (mywidgetCol.Count - 1).ToStrin
End Su
 
Well, I am pretty sure that the stateless nature of web forms is your
problem (not the actually collections).

Basically, each time you submit a page to the server, ASP.NET creates a new
instance of you page class to handle it. When is handled the request, the
class is, in effect, discarded. This means that next to you click Button1,
it's knows nothing of your original collection. This is by design.

If you did not know this, I suggest you go back to some introductory
material on ASP.NET, and get to grips with it. Understanding what is happen
(and *why* its like this) is key to a happy like for an asp.net programmer.

Nick Holmes.

Hanaa said:
I'm new to Asp.net Could you expalin to me what do you mean by web forms are stateless?
The Following Code is the part written fro the Add button it is the same
as the one in the previous menthioned URL.
Dim mywidgetCol As New widgetCollection

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
 
Back
Top