473,472 Members | 2,181 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Accessing Array Items after Response.Redirect

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;
}
}
Nov 22 '05 #1
11 1132
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" <St*****@discussions.microsoft.com> wrote in message
news:59**********************************@microsof t.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 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;
}
}

Nov 22 '05 #2
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" 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.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" <St*****@discussions.microsoft.com> wrote in message
news:59**********************************@microsof t.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 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;
}
}


Nov 22 '05 #3
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" 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.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" <St*****@discussions.microsoft.com> wrote in message
news:59**********************************@microsof t.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 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;
}
}


Nov 22 '05 #4
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" <St*****@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
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" 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.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" <St*****@discussions.microsoft.com> wrote in message
news:59**********************************@microsof t.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 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;
> }
> }


Nov 22 '05 #5
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" wrote:
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" <St*****@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
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" 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.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" <St*****@discussions.microsoft.com> wrote in message
news:59**********************************@microsof t.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 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;
> }
> }


Nov 22 '05 #6
Send me your mail address offlist and i will send you a working example.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.com...
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" wrote:
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" <St*****@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
> 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" 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.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" <St*****@discussions.microsoft.com> wrote in message
>> news:59**********************************@microsof t.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 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;
>> > }
>> > }
>>
>>
>>


Nov 22 '05 #7
St************@uk.fujitsu.com

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

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.com...
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" wrote:
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" <St*****@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
> 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" 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.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" <St*****@discussions.microsoft.com> wrote in message
>> news:59**********************************@microsof t.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 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;
>> > }
>> > }
>>
>>
>>


Nov 22 '05 #8
Can you send that to me please

"Stephen" wrote:
St************@uk.fujitsu.com

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

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.com...
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" wrote:

> 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" <St*****@discussions.microsoft.com> wrote in message
> news:E7**********************************@microsof t.com...
> > 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" 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.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" <St*****@discussions.microsoft.com> wrote in message
> >> news:59**********************************@microsof t.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 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;
> >> > }
> >> > }
> >>
> >>
> >>
>
>
>


Nov 22 '05 #9
Done.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com...
Can you send that to me please

"Stephen" wrote:
St************@uk.fujitsu.com

"Dennis Myrén" wrote:
> Send me your mail address offlist and i will send you a working
> example.
>
> --
> Regards,
> Dennis JD Myrén
> Oslo Kodebureau
> "Stephen" <St*****@discussions.microsoft.com> wrote in message
> news:C7**********************************@microsof t.com...
> >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" wrote:
> >
> >> 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" <St*****@discussions.microsoft.com> wrote in message
> >> news:E7**********************************@microsof t.com...
> >> > 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" 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.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" <St*****@discussions.microsoft.com> wrote in message
> >> >> news:59**********************************@microsof t.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 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;
> >> >> > }
> >> >> > }
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>

Nov 22 '05 #10
I never received it to
St************@uk.fujitsu.com
can you try sending it too
st*********@yahoo.co.uk
please
Thanks very much
"Dennis Myrén" wrote:
Done.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com...
Can you send that to me please

"Stephen" wrote:
St************@uk.fujitsu.com

"Dennis Myrén" wrote:

> Send me your mail address offlist and i will send you a working
> example.
>
> --
> Regards,
> Dennis JD Myrén
> Oslo Kodebureau
> "Stephen" <St*****@discussions.microsoft.com> wrote in message
> news:C7**********************************@microsof t.com...
> >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" wrote:
> >
> >> 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" <St*****@discussions.microsoft.com> wrote in message
> >> news:E7**********************************@microsof t.com...
> >> > 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" 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.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" <St*****@discussions.microsoft.com> wrote in message
> >> >> news:59**********************************@microsof t.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 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;
> >> >> > }
> >> >> > }
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>


Nov 22 '05 #11
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" <St*****@discussions.microsoft.com> wrote in message
news:35**********************************@microsof t.com...
I never received it to
St************@uk.fujitsu.com
can you try sending it too
st*********@yahoo.co.uk
please
Thanks very much
"Dennis Myrén" wrote:
Done.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com...
> Can you send that to me please
>
> "Stephen" wrote:
>
>> St************@uk.fujitsu.com
>>
>> "Dennis Myrén" wrote:
>>
>> > Send me your mail address offlist and i will send you a working
>> > example.
>> >
>> > --
>> > Regards,
>> > Dennis JD Myrén
>> > Oslo Kodebureau
>> > "Stephen" <St*****@discussions.microsoft.com> wrote in message
>> > news:C7**********************************@microsof t.com...
>> > >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" wrote:
>> > >
>> > >> 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" <St*****@discussions.microsoft.com> wrote in message
>> > >> news:E7**********************************@microsof t.com...
>> > >> > 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" 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.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" <St*****@discussions.microsoft.com> wrote in message
>> > >> >> news:59**********************************@microsof t.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 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;
>> > >> >> > }
>> > >> >> > }
>> > >> >>
>> > >> >>
>> > >> >>
>> > >>
>> > >>
>> > >>
>> >
>> >
>> >


Nov 22 '05 #12

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

Similar topics

9
by: Brian Burgess | last post by:
Hi all, Anyone know of any issues with setting the value of a Session object to the value of a submitted form item via 'Session("mySessionObj")=Request.Form("myFrmElem")' ? In my case the...
1
by: Colin Steadman | last post by:
I have a multi-dimensional array that I want to delete items from. To do this I display a form and the user clicks some tick boxes. Then on the delete page I check which tick boxes were...
11
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...
3
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...
4
by: Moe Sizlak | last post by:
Hi There, I am trying to use the to obtain the information from 2 listmenus, if the user makes a selection the page is submitted and then based on the value selected is transfererd to another...
3
by: William | last post by:
Hi I have an ASP.NET application that connects to an Access database. Everything works fine except for the Session object. Data in the session object is lost after I've made a call to the...
6
by: Roman | last post by:
Which is better when passing values between forms?
7
by: Keith Patrick | last post by:
After completely giving up on finding some way in my ASP.Net app to take a query string URL and redirect to it as a POST instead, I went with a system like so: Upon "redirection," all the...
0
by: JLSSCH | last post by:
I am having trouble retrieving the value of a Session variable that ha a string array (the same problem occurs if I use a numeric array stored in it when I redirect from one page to another. The...
1
by: sneha123 | last post by:
There will be some 20 questions and for each question there will be 4 choices.what i want to do is to select multiple answers by clicking the checkbox. i m using asp.net,vb.net pls help me we...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.