473,763 Members | 6,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing ArrayList after redirecting my page c#

I was wondering if someone can help me with an web application design
problem. I have a aspx page which builds up an arraylist called addresses
and outputs the values in the arraylist items to a datagrid. I am using the
viewstate object to store the Arraylist items on the page on postback.

My PROBLEM is that I need to redirect the user to a new aspx page and on
this new page i need to be able to access the items in my arraylist. Is this
possible without using a session object?? Does the viewstate get lost when a
page is redirected?? Below is the code im using to create my arraylist and
store it in viewstate. Can i use Server.Transfer to do this?? If yes is it
recommended??
Is there a simply way of doing this which I am overlooking??

Thanks to everyone who has helped me so far and thanks to any one who can
give me advice or help me now.

Items added to arraylist using contents of textboxes. Then bound to a
datagrid.

protected void cmdExcAdrContin ue_Click(object sender, System.EventArg s e)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];

Address newAddress = new Address();
newAddress.Addr ess1 = this.txtAddress 1.Text.Trim();
newAddress.Addr ess2 = this.txtAddress 2.Text.Trim();
newAddress.Addr ess3 = this.txtAddress 3.Text.Trim();
newAddress.Addr ess4 = this.txtAddress 4.Text.Trim();
newAddress.Addr ess5 = this.txtAddress 5.Text.Trim();
newAddress.Addr ess6 = this.txtAddress 6.Text.Trim();

addresses.Add(n ewAddress);
ViewState["Addresses"] = addresses;

this.dgSearchAd dresses.DataSou rce = addresses;
this.dgSearchAd dresses.DataBin d();

//clear down the textboxes
this.txtAddress 1.Text = "";
this.txtAddress 2.Text = "";
this.txtAddress 3.Text = "";
this.txtAddress 4.Text = "";
this.txtAddress 5.Text = "";
this.txtAddress 6.Text = "";

}

Added to arraylist using contents of another datagrid. Then they are saved
to state and bound to my datagrid.

private void dgResults_ItemC ommand(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
Address a = new Address();
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];
a.Address1 = e.Item.Cells[0].Text;
addresses.Add(a );
dgSearchAddress es.DataSource = addresses;
dgSearchAddress es.DataBind();
checkArrayList( );
}

This is the page load event which enables my page to keeps its state between
posts and build up the arraylist.

private void Page_Load(objec t sender, System.EventArg s e)
{
ArrayList addresses;

// when the page is first loaded only
if( !IsPostBack )
{
addresses = new ArrayList();
ViewState["Addresses"] = addresses;
}
// on subsequent PostBacks:
else
{
addresses = (ArrayList) ViewState["Addresses"];
if( addresses != null )
{
this.dgSearchAd dresses.DataSou rce = addresses;
this.dgSearchAd dresses.DataBin d();
}
}

}

This is the Address class which I use.

[Serializable]
public class Address
{
private string _address1;
public string Address1
{
get{ return _address1; }
set{ _address1 = value; }
}
private string _address2;
public string Address2
{
get{ return _address2; }
set{ _address2 = value; }
}
etc, etc............

//private string _fulladdress;
public string FullAddress
{
get
{
return _address1 + " " + _address2 + " " + _address3 + " " + _address4 + " "
+ _address5 + " " + _address6;
}
}
Nov 16 '05 #1
3 2857
There is a cool way(yes, Server.Transfer you can and will use):
Define a readonly public/internal property in the same class as your
ArrayList
that exposes this ArrayList(which has to be at least module global),example :
public ArrayList List
{
get
{
return _list;
}
}

Go to from where you want to redirect to the second page, add the simple
line
(where WebForm2.aspx is your destination):
Server.Transfer ("WebForm2.aspx ");

Go to WebForm2.aspx.c s, to where you want to retrieve the ArrayList from
"WebForm1" and add this code to obtain it:

WebForm1 webForm1 = base.Context.Ha ndler as WebForm1;
if (null != webForm1) // Sorry, Jon
{
// Add the logic here, example:
foreach (object o in webForm1.List)
{
Response.Write( o.ToString());
}
}

And that is it.
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Stephen" <St*****@discus sions.microsoft .com> wrote in message
news:AB******** *************** ***********@mic rosoft.com...
I was wondering if someone can help me with an web application design
problem. I have a aspx page which builds up an arraylist called addresses
and outputs the values in the arraylist items to a datagrid. I am using
the
viewstate object to store the Arraylist items on the page on postback.

My PROBLEM is that I need to redirect the user to a new aspx page and on
this new page i need to be able to access the items in my arraylist. Is
this
possible without using a session object?? Does the viewstate get lost when
a
page is redirected?? Below is the code im using to create my arraylist and
store it in viewstate. Can i use Server.Transfer to do this?? If yes is
it
recommended??
Is there a simply way of doing this which I am overlooking??

Thanks to everyone who has helped me so far and thanks to any one who can
give me advice or help me now.

Items added to arraylist using contents of textboxes. Then bound to a
datagrid.

protected void cmdExcAdrContin ue_Click(object sender, System.EventArg s e)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];

Address newAddress = new Address();
newAddress.Addr ess1 = this.txtAddress 1.Text.Trim();
newAddress.Addr ess2 = this.txtAddress 2.Text.Trim();
newAddress.Addr ess3 = this.txtAddress 3.Text.Trim();
newAddress.Addr ess4 = this.txtAddress 4.Text.Trim();
newAddress.Addr ess5 = this.txtAddress 5.Text.Trim();
newAddress.Addr ess6 = this.txtAddress 6.Text.Trim();

addresses.Add(n ewAddress);
ViewState["Addresses"] = addresses;

this.dgSearchAd dresses.DataSou rce = addresses;
this.dgSearchAd dresses.DataBin d();

//clear down the textboxes
this.txtAddress 1.Text = "";
this.txtAddress 2.Text = "";
this.txtAddress 3.Text = "";
this.txtAddress 4.Text = "";
this.txtAddress 5.Text = "";
this.txtAddress 6.Text = "";

}

Added to arraylist using contents of another datagrid. Then they are saved
to state and bound to my datagrid.

private void dgResults_ItemC ommand(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
Address a = new Address();
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];
a.Address1 = e.Item.Cells[0].Text;
addresses.Add(a );
dgSearchAddress es.DataSource = addresses;
dgSearchAddress es.DataBind();
checkArrayList( );
}

This is the page load event which enables my page to keeps its state
between
posts and build up the arraylist.

private void Page_Load(objec t sender, System.EventArg s e)
{
ArrayList addresses;

// when the page is first loaded only
if( !IsPostBack )
{
addresses = new ArrayList();
ViewState["Addresses"] = addresses;
}
// on subsequent PostBacks:
else
{
addresses = (ArrayList) ViewState["Addresses"];
if( addresses != null )
{
this.dgSearchAd dresses.DataSou rce = addresses;
this.dgSearchAd dresses.DataBin d();
}
}

}

This is the Address class which I use.

[Serializable]
public class Address
{
private string _address1;
public string Address1
{
get{ return _address1; }
set{ _address1 = value; }
}
private string _address2;
public string Address2
{
get{ return _address2; }
set{ _address2 = value; }
}
etc, etc............

//private string _fulladdress;
public string FullAddress
{
get
{
return _address1 + " " + _address2 + " " + _address3 + " " + _address4 + "
"
+ _address5 + " " + _address6;
}
}

Nov 16 '05 #2
Tried this but Im getting the following runtime error in the browser window
when I run the project: -
Exception of type System.StackOve rflowException was thrown.

Have you any ideas?? Thanks so much for your help

//click event to redirect the page
private void ArrayList_Click (object sender, System.EventArg s e)
{
Server.Transfer ("ArrayListItem sDisplayed.aspx ");
}

//added to my Debtor Enquiry page (WebForm1) at the top
public ArrayList addresses
{
get
{
return addresses;
}
}

//Trying to write the values on the page load event
private void Page_Load(objec t sender, System.EventArg s e)
{
WebForm1 debtor_enquiry = base.Context.Ha ndler as WebForm1;
if (null != debtor_enquiry)
{
// Add some logic here
foreach (object o in debtor_enquiry. addresses)
{
Response.Write( o.ToString());
}
}
}
"Dennis Myrén" wrote:
There is a cool way(yes, Server.Transfer you can and will use):
Define a readonly public/internal property in the same class as your
ArrayList
that exposes this ArrayList(which has to be at least module global),example :
public ArrayList List
{
get
{
return _list;
}
}

Go to from where you want to redirect to the second page, add the simple
line
(where WebForm2.aspx is your destination):
Server.Transfer ("WebForm2.aspx ");

Go to WebForm2.aspx.c s, to where you want to retrieve the ArrayList from
"WebForm1" and add this code to obtain it:

WebForm1 webForm1 = base.Context.Ha ndler as WebForm1;
if (null != webForm1) // Sorry, Jon
{
// Add the logic here, example:
foreach (object o in webForm1.List)
{
Response.Write( o.ToString());
}
}

And that is it.
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Stephen" <St*****@discus sions.microsoft .com> wrote in message
news:AB******** *************** ***********@mic rosoft.com...
I was wondering if someone can help me with an web application design
problem. I have a aspx page which builds up an arraylist called addresses
and outputs the values in the arraylist items to a datagrid. I am using
the
viewstate object to store the Arraylist items on the page on postback.

My PROBLEM is that I need to redirect the user to a new aspx page and on
this new page i need to be able to access the items in my arraylist. Is
this
possible without using a session object?? Does the viewstate get lost when
a
page is redirected?? Below is the code im using to create my arraylist and
store it in viewstate. Can i use Server.Transfer to do this?? If yes is
it
recommended??
Is there a simply way of doing this which I am overlooking??

Thanks to everyone who has helped me so far and thanks to any one who can
give me advice or help me now.

Items added to arraylist using contents of textboxes. Then bound to a
datagrid.

protected void cmdExcAdrContin ue_Click(object sender, System.EventArg s e)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];

Address newAddress = new Address();
newAddress.Addr ess1 = this.txtAddress 1.Text.Trim();
newAddress.Addr ess2 = this.txtAddress 2.Text.Trim();
newAddress.Addr ess3 = this.txtAddress 3.Text.Trim();
newAddress.Addr ess4 = this.txtAddress 4.Text.Trim();
newAddress.Addr ess5 = this.txtAddress 5.Text.Trim();
newAddress.Addr ess6 = this.txtAddress 6.Text.Trim();

addresses.Add(n ewAddress);
ViewState["Addresses"] = addresses;

this.dgSearchAd dresses.DataSou rce = addresses;
this.dgSearchAd dresses.DataBin d();

//clear down the textboxes
this.txtAddress 1.Text = "";
this.txtAddress 2.Text = "";
this.txtAddress 3.Text = "";
this.txtAddress 4.Text = "";
this.txtAddress 5.Text = "";
this.txtAddress 6.Text = "";

}

Added to arraylist using contents of another datagrid. Then they are saved
to state and bound to my datagrid.

private void dgResults_ItemC ommand(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
Address a = new Address();
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];
a.Address1 = e.Item.Cells[0].Text;
addresses.Add(a );
dgSearchAddress es.DataSource = addresses;
dgSearchAddress es.DataBind();
checkArrayList( );
}

This is the page load event which enables my page to keeps its state
between
posts and build up the arraylist.

private void Page_Load(objec t sender, System.EventArg s e)
{
ArrayList addresses;

// when the page is first loaded only
if( !IsPostBack )
{
addresses = new ArrayList();
ViewState["Addresses"] = addresses;
}
// on subsequent PostBacks:
else
{
addresses = (ArrayList) ViewState["Addresses"];
if( addresses != null )
{
this.dgSearchAd dresses.DataSou rce = addresses;
this.dgSearchAd dresses.DataBin d();
}
}

}

This is the Address class which I use.

[Serializable]
public class Address
{
private string _address1;
public string Address1
{
get{ return _address1; }
set{ _address1 = value; }
}
private string _address2;
public string Address2
{
get{ return _address2; }
set{ _address2 = value; }
}
etc, etc............

//private string _fulladdress;
public string FullAddress
{
get
{
return _address1 + " " + _address2 + " " + _address3 + " " + _address4 + "
"
+ _address5 + " " + _address6;
}
}


Nov 16 '05 #3
I think i see the problem here;
You have defined a public property addresses
and in the get clause you are returning addresses.
This leads to an infinite loop, since public property addresses
then is actually calling itself, which is in turn calling itself, and so on.
If the private ArrayList variable is also called addresses, i suggest
you rename the property to Addresses(capit al A) or something else.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Stephen" <St*****@discus sions.microsoft .com> wrote in message
news:C3******** *************** ***********@mic rosoft.com...
Tried this but Im getting the following runtime error in the browser
window
when I run the project: -
Exception of type System.StackOve rflowException was thrown.

Have you any ideas?? Thanks so much for your help

//click event to redirect the page
private void ArrayList_Click (object sender, System.EventArg s e)
{
Server.Transfer ("ArrayListItem sDisplayed.aspx ");
}

//added to my Debtor Enquiry page (WebForm1) at the top
public ArrayList addresses
{
get
{
return addresses;
}
}

//Trying to write the values on the page load event
private void Page_Load(objec t sender, System.EventArg s e)
{
WebForm1 debtor_enquiry = base.Context.Ha ndler as WebForm1;
if (null != debtor_enquiry)
{
// Add some logic here
foreach (object o in debtor_enquiry. addresses)
{
Response.Write( o.ToString());
}
}
}
"Dennis Myrén" wrote:
There is a cool way(yes, Server.Transfer you can and will use):
Define a readonly public/internal property in the same class as your
ArrayList
that exposes this ArrayList(which has to be at least module
global),example :
public ArrayList List
{
get
{
return _list;
}
}

Go to from where you want to redirect to the second page, add the simple
line
(where WebForm2.aspx is your destination):
Server.Transfer ("WebForm2.aspx ");

Go to WebForm2.aspx.c s, to where you want to retrieve the ArrayList from
"WebForm1" and add this code to obtain it:

WebForm1 webForm1 = base.Context.Ha ndler as WebForm1;
if (null != webForm1) // Sorry, Jon
{
// Add the logic here, example:
foreach (object o in webForm1.List)
{
Response.Write( o.ToString());
}
}

And that is it.
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Stephen" <St*****@discus sions.microsoft .com> wrote in message
news:AB******** *************** ***********@mic rosoft.com...
>I was wondering if someone can help me with an web application design
> problem. I have a aspx page which builds up an arraylist called
> addresses
> and outputs the values in the arraylist items to a datagrid. I am
> using
> the
> viewstate object to store the Arraylist items on the page on postback.
>
> My PROBLEM is that I need to redirect the user to a new aspx page and
> on
> this new page i need to be able to access the items in my arraylist. Is
> this
> possible without using a session object?? Does the viewstate get lost
> when
> a
> page is redirected?? Below is the code im using to create my arraylist
> and
> store it in viewstate. Can i use Server.Transfer to do this?? If yes
> is
> it
> recommended??
> Is there a simply way of doing this which I am overlooking??
>
> Thanks to everyone who has helped me so far and thanks to any one who
> can
> give me advice or help me now.
>
> Items added to arraylist using contents of textboxes. Then bound to a
> datagrid.
>
> protected void cmdExcAdrContin ue_Click(object sender, System.EventArg s
> e)
> {
> ArrayList addresses;
> addresses = (ArrayList) ViewState["Addresses"];
>
> Address newAddress = new Address();
> newAddress.Addr ess1 = this.txtAddress 1.Text.Trim();
> newAddress.Addr ess2 = this.txtAddress 2.Text.Trim();
> newAddress.Addr ess3 = this.txtAddress 3.Text.Trim();
> newAddress.Addr ess4 = this.txtAddress 4.Text.Trim();
> newAddress.Addr ess5 = this.txtAddress 5.Text.Trim();
> newAddress.Addr ess6 = this.txtAddress 6.Text.Trim();
>
> addresses.Add(n ewAddress);
> ViewState["Addresses"] = addresses;
>
> this.dgSearchAd dresses.DataSou rce = addresses;
> this.dgSearchAd dresses.DataBin d();
>
> //clear down the textboxes
> this.txtAddress 1.Text = "";
> this.txtAddress 2.Text = "";
> this.txtAddress 3.Text = "";
> this.txtAddress 4.Text = "";
> this.txtAddress 5.Text = "";
> this.txtAddress 6.Text = "";
>
> }
>
> Added to arraylist using contents of another datagrid. Then they are
> saved
> to state and bound to my datagrid.
>
> private void dgResults_ItemC ommand(object source,
> System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
> {
> Address a = new Address();
> ArrayList addresses;
> addresses = (ArrayList) ViewState["Addresses"];
> a.Address1 = e.Item.Cells[0].Text;
> addresses.Add(a );
> dgSearchAddress es.DataSource = addresses;
> dgSearchAddress es.DataBind();
> checkArrayList( );
> }
>
> This is the page load event which enables my page to keeps its state
> between
> posts and build up the arraylist.
>
> private void Page_Load(objec t sender, System.EventArg s e)
> {
> ArrayList addresses;
>
> // when the page is first loaded only
> if( !IsPostBack )
> {
> addresses = new ArrayList();
> ViewState["Addresses"] = addresses;
> }
> // on subsequent PostBacks:
> else
> {
> addresses = (ArrayList) ViewState["Addresses"];
> if( addresses != null )
> {
> this.dgSearchAd dresses.DataSou rce = addresses;
> this.dgSearchAd dresses.DataBin d();
> }
> }
>
> }
>
> This is the Address class which I use.
>
> [Serializable]
> public class Address
> {
> private string _address1;
> public string Address1
> {
> get{ return _address1; }
> set{ _address1 = value; }
> }
> private string _address2;
> public string Address2
> {
> get{ return _address2; }
> set{ _address2 = value; }
> }
> etc, etc............
>
> //private string _fulladdress;
> public string FullAddress
> {
> get
> {
> return _address1 + " " + _address2 + " " + _address3 + " " + _address4
> + "
> "
> + _address5 + " " + _address6;
> }
> }


Nov 16 '05 #4

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

Similar topics

11
2179
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a datagrid. I am using the viewstate object to store the Arraylist items on the page on postback. My PROBLEM is that I need to redirect the user to a new aspx page and on this new page i need to be able to access the items in my arraylist. Is this...
5
6293
by: Jack Addington | last post by:
How do I go about accessing elements of an Arraylist using something other than the index? I have a class that manages a number of subclasses. Those subclasses are stored in an arraylist. The subclass has a key property that is a string. I would like to be able to call Class1.SubClassManager as opposed to Class1.SubClassManager. I tried overriding ArrayList but then I wasn't sure what method to then override or if there was a...
3
3757
by: JJ | last post by:
Hi, I have created an Arraylist object from an Arraylist class. I added rows to the arraylist object and I need to find a particular record in my arraylist. How do I do this? Also if I was in the middle of building the arraylist and wanted to call the last record added to arraylist object how can I do this? Thanks,
0
1147
by: rlueneberg | last post by:
I am getting this error when trying to add typed object "Questions" to Arraylist QuestionsList: Object reference not set to an instance of an object. --> r.QuestionsList.Add(q); I tried using r.QuestionsList.Add(q) to add a new instance within the loop but it does not work. Any help will be appreciated...
5
2765
by: Siva | last post by:
Hello I have a dropdownlist inside the gridview as a template column defined as follows: <asp:TemplateField HeaderText="Choose Location"> <ItemTemplate> <asp:DropDownList ID="ddlChooseLoc" runat="server"> </asp:DropDownList> </ItemTemplate> </asp:TemplateField> I have the gridview inside of a master page- content hierarchy.
3
2815
by: Alex | last post by:
Hi all, I'm trying to create an arraylist of a user control class... I'm able to define the list and add objects (panels) to it, but I can access and of the panel properties using an index... Is there a way to do this, or do I need to copy each node into an interim handle of the correct class before manipulating it? ie,
1
8164
JoeMac3313
by: JoeMac3313 | last post by:
I have been flailing widely about trying to get the information from the arrayList to the jsp page to print to a table on the jsp page. The information on the txt file is Name:Department:Job Title:Year Hired:Gender
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
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
10144
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
9997
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8821
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...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
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
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
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

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.