interim values

J

Jon Paal

I am using a custom server control in my webpage which renders some html.

while it creates the html, it develops an arraylist of values. Is there a way to capture the arraylist from the control so it can
also be used on the same web page ?

this needs to happen in the post back.
 
K

Kevin Spencer

If the array of values is a public property of the class, the Page can
access it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer

Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.
 
J

Jon Paal

I have the arraylist defined as a public property and I can verify that the list has values when the server control is running, but
when I try to use the arraylist in my webpage, it is empty .

What am I doing wrong with the properties ?

I create the property wth the webpage by:

................
Dim arrTempList As New ArrayList()
oThis.myArrayList = arrTempList
...............


I have the the property defined in the control as:

.....................
Public arrChartList As Arraylist
Public Property myArrayList As ArrayList
Get
Return arrChartList
End Get
Set
arrChartList = value
End Set
End Property
.......................
 
K

Kevin Spencer

Dim arrTempList As New ArrayList()
oThis.myArrayList = arrTempList

You seem to be initializing an ArrayList somewhere in the code of your
Control. When you initialize it, it is empty. You then assing it to a public
property "myArrayList" (not sure where the "o" came from, but if the code
compiles, I'm assuming it's not in your actual code). The public property
exposes a private ("arrChartList") ArrayList. Kludgy, but it will work. So
far.

Now, what you have told me is that when you "try to use the arraylist" in
your "webpage" it is empty. Why that is, I can't tell from what you've
posted, as nothing you've posted indicates how it is supposed to be
populated, at what point in the execution cycle it is populated, if and how
it is persisted across PostBacks, etc.

At this point, all I can give you is a pointer or 2 on your initialization
of the ArrayList:
Dim arrTempList As New ArrayList()
oThis.myArrayList = arrTempList

This is all completely unnecessary. Consider the following:

Protected arrChartList As New Arraylist()
Public Property myArrayList As ArrayList
Get
Return arrChartList
End Get
Set
arrChartList = value
End Set
End Property

or, if you want to be even more simple, since you declared the
"arrChartList" as Public:

Public arrChartList As New Arraylist()

Why? Well, first, a field and a variable are the same thing in different
scopes. When you say:

Dim arrTempList As New ArrayList()

at class scope, you are saying the same thing as:

Private arrTempList As New ArrayList()

So, in essence, you've declared 2 fields ("arrTempList" and "arrChartList"),
and simply assigned the value of one to the other. Now you have 2 fields
that point to the same ArrayList.

Second, when you assign it to the Public Property:

This.myArrayList = arrTempList

You are invoking the Setter of the Property to assign the value of the field
"arrChartList". In other words, you are using indirection, and calling a
method to assign a value which could be assigned less expensively by simple
assignment. But again, it is not necessary to declare 2 fields.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer

Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.
 
J

Jon Paal

All of this activity happens in the postback.
I'm using vb.net so "oThis" is simply an instance of the control.

I know the coding is sloppy, but I'm groping around trying to get this to work.

The property ideally should be populated from a function in the control. The function requires use of all other properties.

I can sort of get the arraylist if I assign it to a session value inside the control and then display the session value from the web
page. Unfortunately, it's always displaying the "previous" value ( last set of user choices) unless I refresh the page, then I get
the current value.

I can't understand why it's impossible to get the interim value back from the property during the postback. I even tried creating a
separate instance of the object and although I can confirm it is running correctly I still can't get back a value from the property.
?????


Is this a problem because the control has been designed to override the render for outputting the html ??
 

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

Top