Accessing Array Items after Response.Redirect

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

Guest

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 cmdExcAdrContinue_Click(object sender, System.EventArgs e)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];

Address newAddress = new Address();
newAddress.Address1 = this.txtAddress1.Text.Trim();
newAddress.Address2 = this.txtAddress2.Text.Trim();
newAddress.Address3 = this.txtAddress3.Text.Trim();
newAddress.Address4 = this.txtAddress4.Text.Trim();
newAddress.Address5 = this.txtAddress5.Text.Trim();
newAddress.Address6 = this.txtAddress6.Text.Trim();

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

this.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();

//clear down the textboxes
this.txtAddress1.Text = "";
this.txtAddress2.Text = "";
this.txtAddress3.Text = "";
this.txtAddress4.Text = "";
this.txtAddress5.Text = "";
this.txtAddress6.Text = "";

}

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

private void dgResults_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Address a = new Address();
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];
a.Address1 = e.Item.Cells[0].Text;
addresses.Add(a);
dgSearchAddresses.DataSource = addresses;
dgSearchAddresses.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(object sender, System.EventArgs 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.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();
}
}

}

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;
}
}
 
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.cs, to where you want to retrieve the ArrayList from
"WebForm1" and add this code to obtain it:

WebForm1 webForm1 = base.Context.Handler 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 said:
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 cmdExcAdrContinue_Click(object sender, System.EventArgs e)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];

Address newAddress = new Address();
newAddress.Address1 = this.txtAddress1.Text.Trim();
newAddress.Address2 = this.txtAddress2.Text.Trim();
newAddress.Address3 = this.txtAddress3.Text.Trim();
newAddress.Address4 = this.txtAddress4.Text.Trim();
newAddress.Address5 = this.txtAddress5.Text.Trim();
newAddress.Address6 = this.txtAddress6.Text.Trim();

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

this.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();

//clear down the textboxes
this.txtAddress1.Text = "";
this.txtAddress2.Text = "";
this.txtAddress3.Text = "";
this.txtAddress4.Text = "";
this.txtAddress5.Text = "";
this.txtAddress6.Text = "";

}

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

private void dgResults_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Address a = new Address();
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];
a.Address1 = e.Item.Cells[0].Text;
addresses.Add(a);
dgSearchAddresses.DataSource = addresses;
dgSearchAddresses.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(object sender, System.EventArgs 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.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();
}
}

}

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;
}
}
 
Tried this but Im getting the following runtime error in the browser window
when I run the project: -
Exception of type System.StackOverflowException 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.EventArgs e)
{
Server.Transfer("ArrayListItemsDisplayed.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(object sender, System.EventArgs e)
{
WebForm1 debtor_enquiry = base.Context.Handler as WebForm1;
if (null != debtor_enquiry)
{
// Add some logic here
foreach (object o in debtor_enquiry.addresses)
{
Response.Write(o.ToString());
}
}
}

Dennis Myrén said:
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.cs, to where you want to retrieve the ArrayList from
"WebForm1" and add this code to obtain it:

WebForm1 webForm1 = base.Context.Handler 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 said:
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 cmdExcAdrContinue_Click(object sender, System.EventArgs e)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];

Address newAddress = new Address();
newAddress.Address1 = this.txtAddress1.Text.Trim();
newAddress.Address2 = this.txtAddress2.Text.Trim();
newAddress.Address3 = this.txtAddress3.Text.Trim();
newAddress.Address4 = this.txtAddress4.Text.Trim();
newAddress.Address5 = this.txtAddress5.Text.Trim();
newAddress.Address6 = this.txtAddress6.Text.Trim();

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

this.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();

//clear down the textboxes
this.txtAddress1.Text = "";
this.txtAddress2.Text = "";
this.txtAddress3.Text = "";
this.txtAddress4.Text = "";
this.txtAddress5.Text = "";
this.txtAddress6.Text = "";

}

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

private void dgResults_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Address a = new Address();
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];
a.Address1 = e.Item.Cells[0].Text;
addresses.Add(a);
dgSearchAddresses.DataSource = addresses;
dgSearchAddresses.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(object sender, System.EventArgs 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.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();
}
}

}

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;
}
}
 
Tried this but Im getting the following runtime error in the browser window
when I run the project: -
Exception of type System.StackOverflowException 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.EventArgs e)
{
Server.Transfer("ArrayListItemsDisplayed.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(object sender, System.EventArgs e)
{
WebForm1 debtor_enquiry = base.Context.Handler as WebForm1;
if (null != debtor_enquiry)
{
// Add some logic here
foreach (object o in debtor_enquiry.addresses)
{
Response.Write(o.ToString());
}
}
}

Dennis Myrén said:
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.cs, to where you want to retrieve the ArrayList from
"WebForm1" and add this code to obtain it:

WebForm1 webForm1 = base.Context.Handler 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 said:
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 cmdExcAdrContinue_Click(object sender, System.EventArgs e)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];

Address newAddress = new Address();
newAddress.Address1 = this.txtAddress1.Text.Trim();
newAddress.Address2 = this.txtAddress2.Text.Trim();
newAddress.Address3 = this.txtAddress3.Text.Trim();
newAddress.Address4 = this.txtAddress4.Text.Trim();
newAddress.Address5 = this.txtAddress5.Text.Trim();
newAddress.Address6 = this.txtAddress6.Text.Trim();

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

this.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();

//clear down the textboxes
this.txtAddress1.Text = "";
this.txtAddress2.Text = "";
this.txtAddress3.Text = "";
this.txtAddress4.Text = "";
this.txtAddress5.Text = "";
this.txtAddress6.Text = "";

}

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

private void dgResults_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Address a = new Address();
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];
a.Address1 = e.Item.Cells[0].Text;
addresses.Add(a);
dgSearchAddresses.DataSource = addresses;
dgSearchAddresses.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(object sender, System.EventArgs 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.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();
}
}

}

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;
}
}
 
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(capital A) or something else.


--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Stephen said:
Tried this but Im getting the following runtime error in the browser
window
when I run the project: -
Exception of type System.StackOverflowException 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.EventArgs e)
{
Server.Transfer("ArrayListItemsDisplayed.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(object sender, System.EventArgs e)
{
WebForm1 debtor_enquiry = base.Context.Handler as WebForm1;
if (null != debtor_enquiry)
{
// Add some logic here
foreach (object o in debtor_enquiry.addresses)
{
Response.Write(o.ToString());
}
}
}

Dennis Myrén said:
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.cs, to where you want to retrieve the ArrayList from
"WebForm1" and add this code to obtain it:

WebForm1 webForm1 = base.Context.Handler 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 said:
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 cmdExcAdrContinue_Click(object sender, System.EventArgs
e)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];

Address newAddress = new Address();
newAddress.Address1 = this.txtAddress1.Text.Trim();
newAddress.Address2 = this.txtAddress2.Text.Trim();
newAddress.Address3 = this.txtAddress3.Text.Trim();
newAddress.Address4 = this.txtAddress4.Text.Trim();
newAddress.Address5 = this.txtAddress5.Text.Trim();
newAddress.Address6 = this.txtAddress6.Text.Trim();

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

this.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();

//clear down the textboxes
this.txtAddress1.Text = "";
this.txtAddress2.Text = "";
this.txtAddress3.Text = "";
this.txtAddress4.Text = "";
this.txtAddress5.Text = "";
this.txtAddress6.Text = "";

}

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

private void dgResults_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Address a = new Address();
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];
a.Address1 = e.Item.Cells[0].Text;
addresses.Add(a);
dgSearchAddresses.DataSource = addresses;
dgSearchAddresses.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(object sender, System.EventArgs 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.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();
}
}

}

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;
}
}
 
I changed that as suggested too: -
private ArrayList Addresses;
public ArrayList addresses
{
get
{
return Addresses;
}
}
Is this what you meant??

However Im now getting this runtime error: -
Object reference not set to an instance of an object.

for the line: -
foreach (object o in debtor_enquiry.addresses)

Have you any ideas what i've done wrong now??

Thanks again for your help

Dennis Myrén said:
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(capital A) or something else.


--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Stephen said:
Tried this but Im getting the following runtime error in the browser
window
when I run the project: -
Exception of type System.StackOverflowException 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.EventArgs e)
{
Server.Transfer("ArrayListItemsDisplayed.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(object sender, System.EventArgs e)
{
WebForm1 debtor_enquiry = base.Context.Handler as WebForm1;
if (null != debtor_enquiry)
{
// Add some logic here
foreach (object o in debtor_enquiry.addresses)
{
Response.Write(o.ToString());
}
}
}

Dennis Myrén said:
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.cs, to where you want to retrieve the ArrayList from
"WebForm1" and add this code to obtain it:

WebForm1 webForm1 = base.Context.Handler 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
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 cmdExcAdrContinue_Click(object sender, System.EventArgs
e)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];

Address newAddress = new Address();
newAddress.Address1 = this.txtAddress1.Text.Trim();
newAddress.Address2 = this.txtAddress2.Text.Trim();
newAddress.Address3 = this.txtAddress3.Text.Trim();
newAddress.Address4 = this.txtAddress4.Text.Trim();
newAddress.Address5 = this.txtAddress5.Text.Trim();
newAddress.Address6 = this.txtAddress6.Text.Trim();

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

this.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();

//clear down the textboxes
this.txtAddress1.Text = "";
this.txtAddress2.Text = "";
this.txtAddress3.Text = "";
this.txtAddress4.Text = "";
this.txtAddress5.Text = "";
this.txtAddress6.Text = "";

}

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

private void dgResults_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Address a = new Address();
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];
a.Address1 = e.Item.Cells[0].Text;
addresses.Add(a);
dgSearchAddresses.DataSource = addresses;
dgSearchAddresses.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(object sender, System.EventArgs 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.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();
}
}

}

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;
}
}
 
Send me your mail address offlist and i will send you a working example.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Stephen said:
I changed that as suggested too: -
private ArrayList Addresses;
public ArrayList addresses
{
get
{
return Addresses;
}
}
Is this what you meant??

However Im now getting this runtime error: -
Object reference not set to an instance of an object.

for the line: -
foreach (object o in debtor_enquiry.addresses)

Have you any ideas what i've done wrong now??

Thanks again for your help

Dennis Myrén said:
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(capital A) or something else.


--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Stephen said:
Tried this but Im getting the following runtime error in the browser
window
when I run the project: -
Exception of type System.StackOverflowException 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.EventArgs e)
{
Server.Transfer("ArrayListItemsDisplayed.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(object sender, System.EventArgs e)
{
WebForm1 debtor_enquiry = base.Context.Handler as WebForm1;
if (null != debtor_enquiry)
{
// Add some logic here
foreach (object o in debtor_enquiry.addresses)
{
Response.Write(o.ToString());
}
}
}

:

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.cs, to where you want to retrieve the ArrayList
from
"WebForm1" and add this code to obtain it:

WebForm1 webForm1 = base.Context.Handler 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
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 cmdExcAdrContinue_Click(object sender,
System.EventArgs
e)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];

Address newAddress = new Address();
newAddress.Address1 = this.txtAddress1.Text.Trim();
newAddress.Address2 = this.txtAddress2.Text.Trim();
newAddress.Address3 = this.txtAddress3.Text.Trim();
newAddress.Address4 = this.txtAddress4.Text.Trim();
newAddress.Address5 = this.txtAddress5.Text.Trim();
newAddress.Address6 = this.txtAddress6.Text.Trim();

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

this.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();

//clear down the textboxes
this.txtAddress1.Text = "";
this.txtAddress2.Text = "";
this.txtAddress3.Text = "";
this.txtAddress4.Text = "";
this.txtAddress5.Text = "";
this.txtAddress6.Text = "";

}

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

private void dgResults_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Address a = new Address();
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];
a.Address1 = e.Item.Cells[0].Text;
addresses.Add(a);
dgSearchAddresses.DataSource = addresses;
dgSearchAddresses.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(object sender, System.EventArgs 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.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();
}
}

}

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;
}
}
 
(e-mail address removed)

Dennis Myrén said:
Send me your mail address offlist and i will send you a working example.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Stephen said:
I changed that as suggested too: -
private ArrayList Addresses;
public ArrayList addresses
{
get
{
return Addresses;
}
}
Is this what you meant??

However Im now getting this runtime error: -
Object reference not set to an instance of an object.

for the line: -
foreach (object o in debtor_enquiry.addresses)

Have you any ideas what i've done wrong now??

Thanks again for your help

Dennis Myrén said:
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(capital A) or something else.


--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Tried this but Im getting the following runtime error in the browser
window
when I run the project: -
Exception of type System.StackOverflowException 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.EventArgs e)
{
Server.Transfer("ArrayListItemsDisplayed.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(object sender, System.EventArgs e)
{
WebForm1 debtor_enquiry = base.Context.Handler as WebForm1;
if (null != debtor_enquiry)
{
// Add some logic here
foreach (object o in debtor_enquiry.addresses)
{
Response.Write(o.ToString());
}
}
}

:

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.cs, to where you want to retrieve the ArrayList
from
"WebForm1" and add this code to obtain it:

WebForm1 webForm1 = base.Context.Handler 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
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 cmdExcAdrContinue_Click(object sender,
System.EventArgs
e)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];

Address newAddress = new Address();
newAddress.Address1 = this.txtAddress1.Text.Trim();
newAddress.Address2 = this.txtAddress2.Text.Trim();
newAddress.Address3 = this.txtAddress3.Text.Trim();
newAddress.Address4 = this.txtAddress4.Text.Trim();
newAddress.Address5 = this.txtAddress5.Text.Trim();
newAddress.Address6 = this.txtAddress6.Text.Trim();

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

this.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();

//clear down the textboxes
this.txtAddress1.Text = "";
this.txtAddress2.Text = "";
this.txtAddress3.Text = "";
this.txtAddress4.Text = "";
this.txtAddress5.Text = "";
this.txtAddress6.Text = "";

}

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

private void dgResults_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Address a = new Address();
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];
a.Address1 = e.Item.Cells[0].Text;
addresses.Add(a);
dgSearchAddresses.DataSource = addresses;
dgSearchAddresses.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(object sender, System.EventArgs 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.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();
}
}

}

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;
}
}
 
Can you send that to me please

Stephen said:
(e-mail address removed)

Dennis Myrén said:
Send me your mail address offlist and i will send you a working example.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Stephen said:
I changed that as suggested too: -
private ArrayList Addresses;
public ArrayList addresses
{
get
{
return Addresses;
}
}
Is this what you meant??

However Im now getting this runtime error: -
Object reference not set to an instance of an object.

for the line: -
foreach (object o in debtor_enquiry.addresses)

Have you any ideas what i've done wrong now??

Thanks again for your help

:

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(capital A) or something else.


--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Tried this but Im getting the following runtime error in the browser
window
when I run the project: -
Exception of type System.StackOverflowException 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.EventArgs e)
{
Server.Transfer("ArrayListItemsDisplayed.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(object sender, System.EventArgs e)
{
WebForm1 debtor_enquiry = base.Context.Handler as WebForm1;
if (null != debtor_enquiry)
{
// Add some logic here
foreach (object o in debtor_enquiry.addresses)
{
Response.Write(o.ToString());
}
}
}

:

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.cs, to where you want to retrieve the ArrayList
from
"WebForm1" and add this code to obtain it:

WebForm1 webForm1 = base.Context.Handler 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
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 cmdExcAdrContinue_Click(object sender,
System.EventArgs
e)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];

Address newAddress = new Address();
newAddress.Address1 = this.txtAddress1.Text.Trim();
newAddress.Address2 = this.txtAddress2.Text.Trim();
newAddress.Address3 = this.txtAddress3.Text.Trim();
newAddress.Address4 = this.txtAddress4.Text.Trim();
newAddress.Address5 = this.txtAddress5.Text.Trim();
newAddress.Address6 = this.txtAddress6.Text.Trim();

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

this.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();

//clear down the textboxes
this.txtAddress1.Text = "";
this.txtAddress2.Text = "";
this.txtAddress3.Text = "";
this.txtAddress4.Text = "";
this.txtAddress5.Text = "";
this.txtAddress6.Text = "";

}

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

private void dgResults_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Address a = new Address();
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];
a.Address1 = e.Item.Cells[0].Text;
addresses.Add(a);
dgSearchAddresses.DataSource = addresses;
dgSearchAddresses.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(object sender, System.EventArgs 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.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();
}
}

}

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;
}
}
 
Done.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Stephen said:
Can you send that to me please

Stephen said:
(e-mail address removed)

Dennis Myrén said:
Send me your mail address offlist and i will send you a working
example.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
I changed that as suggested too: -
private ArrayList Addresses;
public ArrayList addresses
{
get
{
return Addresses;
}
}
Is this what you meant??

However Im now getting this runtime error: -
Object reference not set to an instance of an object.

for the line: -
foreach (object o in debtor_enquiry.addresses)

Have you any ideas what i've done wrong now??

Thanks again for your help

:

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(capital A) or something else.


--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Tried this but Im getting the following runtime error in the
browser
window
when I run the project: -
Exception of type System.StackOverflowException 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.EventArgs e)
{
Server.Transfer("ArrayListItemsDisplayed.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(object sender, System.EventArgs e)
{
WebForm1 debtor_enquiry = base.Context.Handler as WebForm1;
if (null != debtor_enquiry)
{
// Add some logic here
foreach (object o in debtor_enquiry.addresses)
{
Response.Write(o.ToString());
}
}
}

:

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.cs, to where you want to retrieve the
ArrayList
from
"WebForm1" and add this code to obtain it:

WebForm1 webForm1 = base.Context.Handler 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
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 cmdExcAdrContinue_Click(object sender,
System.EventArgs
e)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];

Address newAddress = new Address();
newAddress.Address1 = this.txtAddress1.Text.Trim();
newAddress.Address2 = this.txtAddress2.Text.Trim();
newAddress.Address3 = this.txtAddress3.Text.Trim();
newAddress.Address4 = this.txtAddress4.Text.Trim();
newAddress.Address5 = this.txtAddress5.Text.Trim();
newAddress.Address6 = this.txtAddress6.Text.Trim();

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

this.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();

//clear down the textboxes
this.txtAddress1.Text = "";
this.txtAddress2.Text = "";
this.txtAddress3.Text = "";
this.txtAddress4.Text = "";
this.txtAddress5.Text = "";
this.txtAddress6.Text = "";

}

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

private void dgResults_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Address a = new Address();
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];
a.Address1 = e.Item.Cells[0].Text;
addresses.Add(a);
dgSearchAddresses.DataSource = addresses;
dgSearchAddresses.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(object sender, System.EventArgs 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.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();
}
}

}

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;
}
}
 
I never received it to
(e-mail address removed)
can you try sending it too
(e-mail address removed)
please
Thanks very much


Dennis Myrén said:
Done.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Stephen said:
Can you send that to me please

Stephen said:
(e-mail address removed)

:

Send me your mail address offlist and i will send you a working
example.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
I changed that as suggested too: -
private ArrayList Addresses;
public ArrayList addresses
{
get
{
return Addresses;
}
}
Is this what you meant??

However Im now getting this runtime error: -
Object reference not set to an instance of an object.

for the line: -
foreach (object o in debtor_enquiry.addresses)

Have you any ideas what i've done wrong now??

Thanks again for your help

:

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(capital A) or something else.


--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Tried this but Im getting the following runtime error in the
browser
window
when I run the project: -
Exception of type System.StackOverflowException 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.EventArgs e)
{
Server.Transfer("ArrayListItemsDisplayed.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(object sender, System.EventArgs e)
{
WebForm1 debtor_enquiry = base.Context.Handler as WebForm1;
if (null != debtor_enquiry)
{
// Add some logic here
foreach (object o in debtor_enquiry.addresses)
{
Response.Write(o.ToString());
}
}
}

:

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.cs, to where you want to retrieve the
ArrayList
from
"WebForm1" and add this code to obtain it:

WebForm1 webForm1 = base.Context.Handler 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
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 cmdExcAdrContinue_Click(object sender,
System.EventArgs
e)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];

Address newAddress = new Address();
newAddress.Address1 = this.txtAddress1.Text.Trim();
newAddress.Address2 = this.txtAddress2.Text.Trim();
newAddress.Address3 = this.txtAddress3.Text.Trim();
newAddress.Address4 = this.txtAddress4.Text.Trim();
newAddress.Address5 = this.txtAddress5.Text.Trim();
newAddress.Address6 = this.txtAddress6.Text.Trim();

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

this.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();

//clear down the textboxes
this.txtAddress1.Text = "";
this.txtAddress2.Text = "";
this.txtAddress3.Text = "";
this.txtAddress4.Text = "";
this.txtAddress5.Text = "";
this.txtAddress6.Text = "";

}

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

private void dgResults_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Address a = new Address();
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];
a.Address1 = e.Item.Cells[0].Text;
addresses.Add(a);
dgSearchAddresses.DataSource = addresses;
dgSearchAddresses.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(object sender, System.EventArgs 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.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();
}
}

}

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;
}
}
 
I will just post the code-behind files inline here:

<code_WebForm1>

using System.Collections;

namespace TestApp
{

public class WebForm1 : System.Web.UI.Page
{

protected System.Web.UI.WebControls.Button Button1;

private ArrayList _addresses = new ArrayList();

public ArrayList Addresses
{
get
{
return _addresses;
}
}

private void Page_Load ( object sender, System.EventArgs e )
{
// Just loading some dummy data:
_addresses.Add("Wall Street 54");
_addresses.Add("Sunset Boulevard 800");
}

override protected void OnInit ( System.EventArgs e )
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent ( )
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}

private void Button1_Click ( object sender, System.EventArgs e )
{
Server.Transfer("WebForm2.aspx");
}
}
}
</code_WebForm1>
<code_WebForm2>

namespace TestApp
{

public class WebForm2 : System.Web.UI.Page
{

private void Page_Load ( object sender, System.EventArgs e )
{
WebForm1 webForm1 = base.Context.Handler as WebForm1;
if (null != webForm1) /* OK: It was WebForm1 who transfered us here. */
{
foreach (string address in webForm1.Addresses)
{
Response.Write(address);
Response.Write("<br />\n");
}
}
else /* ERROR: It was not WebForm1 who transfered us here. */
{
Response.Write("Invalid referrer!");
Response.Flush();
}
}

override protected void OnInit ( System.EventArgs e )
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}

}
}
</code_WebForm2>


--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Stephen said:
I never received it to
(e-mail address removed)
can you try sending it too
(e-mail address removed)
please
Thanks very much


Dennis Myrén said:
Done.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Stephen said:
Can you send that to me please

:

(e-mail address removed)

:

Send me your mail address offlist and i will send you a working
example.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
I changed that as suggested too: -
private ArrayList Addresses;
public ArrayList addresses
{
get
{
return Addresses;
}
}
Is this what you meant??

However Im now getting this runtime error: -
Object reference not set to an instance of an object.

for the line: -
foreach (object o in debtor_enquiry.addresses)

Have you any ideas what i've done wrong now??

Thanks again for your help

:

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(capital A) or something
else.


--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Tried this but Im getting the following runtime error in the
browser
window
when I run the project: -
Exception of type System.StackOverflowException 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.EventArgs e)
{
Server.Transfer("ArrayListItemsDisplayed.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(object sender, System.EventArgs e)
{
WebForm1 debtor_enquiry = base.Context.Handler as WebForm1;
if (null != debtor_enquiry)
{
// Add some logic here
foreach (object o in debtor_enquiry.addresses)
{
Response.Write(o.ToString());
}
}
}

:

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.cs, to where you want to retrieve the
ArrayList
from
"WebForm1" and add this code to obtain it:

WebForm1 webForm1 = base.Context.Handler 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
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 cmdExcAdrContinue_Click(object sender,
System.EventArgs
e)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];

Address newAddress = new Address();
newAddress.Address1 = this.txtAddress1.Text.Trim();
newAddress.Address2 = this.txtAddress2.Text.Trim();
newAddress.Address3 = this.txtAddress3.Text.Trim();
newAddress.Address4 = this.txtAddress4.Text.Trim();
newAddress.Address5 = this.txtAddress5.Text.Trim();
newAddress.Address6 = this.txtAddress6.Text.Trim();

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

this.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();

//clear down the textboxes
this.txtAddress1.Text = "";
this.txtAddress2.Text = "";
this.txtAddress3.Text = "";
this.txtAddress4.Text = "";
this.txtAddress5.Text = "";
this.txtAddress6.Text = "";

}

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

private void dgResults_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Address a = new Address();
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];
a.Address1 = e.Item.Cells[0].Text;
addresses.Add(a);
dgSearchAddresses.DataSource = addresses;
dgSearchAddresses.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(object sender, System.EventArgs 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.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind();
}
}

}

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;
}
}
 
Back
Top