RE: Arraylist issue
From: Prakash.NET (PrakashNET_at_discussions.microsoft.com)
Date: 12/31/04
- Next message: Erik Read: "Class Library as COM Object"
- Previous message: Ken Dopierala Jr.: "Re: bandwidth calculation"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 30 Dec 2004 20:35:02 -0800
Hi,
Storing it in ViewState will be a good choice. The arraylist will be sent
to client and then returned back. It will cause extra data to be sent to
client. The other options are Cache, Session and Application.
To add to view state, the command is ViewState("<variablename>") =
<arraylist>
Hope it helps
Prakash.C
"Dave" wrote:
> Hi,
>
> Yes, I understand it is a stateless protocol (I have
> extensive classic asp), but I would have thought that a
> global variable would have held itself, probably using
> the viewstate. Perhaps not. I thought the idea of
> webforms was to make it work like winforms, in that
> setting a value would hold between pages.
>
> Perhaps I should make an invisible datagrid (or
> datalist), populate it with the arraylist, then read it
> back (as grids appear to hold state)
>
> Cheers.
> Dave.
> http://www.NorthamptonFOCUS.com
>
> >-----Original Message-----
> >Hi Dave,
> >
> >
> >As you know the HTTP protocol is stateless protocol, so
> with each request we
> >need to build all required objects and populate variable
> from scratch. Even
> >if your variables or objects are global they will not be
> available in next
> >postback request.
> >
> >To pass this data from one request to next request we
> need to store it
> >somewhere. There are few possible ways to do it.
> Depending on your
> >requirements you can use the most appropriate method.
> >
> >1. Use Session to store your data.
> >2. Use Cache to store in application cache.
> >3. Make it a static variable of global application
> object.
> >4. Serialize the data and store it either in
> viewstate or file system, and
> >then deserialize in next request.
> >
> >Hope it will help.
> >
> >--
> >Cheers,
> >Rahul Anand
> >
> >"Dave" wrote:
> >
> >> Hi,
> >>
> >> I thought the idea of making the arraylist global
> would
> >> negate the issue of postback and make it survivable. I
> am
> >> not filling the arraylist on the page_load, I am using
> an
> >> onclick event to fill the arraylist, then another
> onclick
> >> to index the position and read the arraylist.
> >>
> >> How else can I make the arraylist survivable?
> >>
> >> Thanks.
> >> Best regards,
> >> Dave Colliver.
> >> http://www.AshfieldFOCUS.com
> >>
> >> >-----Original Message-----
> >> >Hi,
> >> >
> >> > When you click the "Next" button, the post back
> >> occurs, and hence the
> >> >arraylist is again filled with empty. Check for
> PostBack
> >> event of Page, and
> >> >fill the arraylist accordingly.
> >> >
> >> >Prakash.C
> >> >
> >> >"Dave" wrote:
> >> >
> >> >> Hi all,
> >> >>
> >> >> I have...
> >> >>
> >> >> using System.Collections;
> >> >> namespace MyApp.Templates
> >> >> {
> >> >> public class MyPage : System.Web.UI.Page
> >> >> {
> >> >> ArrayList MyArray = new ArrayList();
> >> >> int MyPointer;
> >> >>
> >> >> private void FillArray_Click(object sender,
> >> >> EventArgs e)
> >> >> {
> >> >> foreach (DataGridItem i in MyGrid.Items)
> >> >> {
> >> >> CheckBox cbSelectRows = (CheckBox)
> >> >> i.FindControl("cbSelect");
> >> >> if (cbSelectRows.Checked)
> >> >> {
> >> >> MyArray.Add(((Label)
> i.FindControl
> >> >> ("DFESLabel")).Text.ToString());
> >> >> Trace.Warn(((Label)
> i.FindControl
> >> >> ("DFESLabel")).Text.ToString());
> >> >> }
> >> >> }
> >> >> MyPointer = 0;
> >> >> Response.Write (MyArray
> [MyPointer].ToString
> >> >> ());
> >> >> }
> >> >>
> >> >>
> >> >> private void NextButton_Click(object
> sender,
> >> >> EventArgs e)
> >> >> {
> >> >> Trace.Warn("ArrayCount",
> >> >> MyArray.Count.ToString());
> >> >> MyPointer ++;
> >> >> Trace.Warn(MyPointer.ToString());
> >> >> Response.Write(MyArray
> MyPointer].ToString
> >> ());
> >> >> }
> >> >>
> >> >> }
> >> >> }
> >> >>
> >> >>
> >> >> Notice my arraylist is defined outside of any
> >> functions
> >> >> or events. This is to make it useable in any of the
> >> >> functions.
> >> >>
> >> >> When I do FillArray_Click, the array fills up
> >> correctly.
> >> >>
> >> >> If however, once I have filled the arraylist, then
> >> click
> >> >> NextButton, the arraylist appears to be empty. How
> >> come?
> >> >> I have already filled it, it is a global arraylist,
> so
> >> to
> >> >> me, it should remain filled.
> >> >>
> >> >> This is C# in ASP.NET.
> >> >>
> >> >> Thanks for any help.
> >> >> Regards,
> >> >> Dave Colliver.
> >> >> http://www.BlackpoolFOCUS.com
> >> >>
> >> >>
> >> >.
> >> >
> >>
> >.
> >
>
- Next message: Erik Read: "Class Library as COM Object"
- Previous message: Ken Dopierala Jr.: "Re: bandwidth calculation"
- Messages sorted by: [ date ] [ thread ]