473,287 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

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;
}
}
Jul 21 '05 #1
11 2125
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;
}
}

Jul 21 '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;
}
}


Jul 21 '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;
}
}


Jul 21 '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;
> }
> }


Jul 21 '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;
> }
> }


Jul 21 '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;
>> > }
>> > }
>>
>>
>>


Jul 21 '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;
>> > }
>> > }
>>
>>
>>


Jul 21 '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;
> >> > }
> >> > }
> >>
> >>
> >>
>
>
>


Jul 21 '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;
> >> >> > }
> >> >> > }
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>

Jul 21 '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;
> >> >> > }
> >> >> > }
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>


Jul 21 '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;
>> > >> >> > }
>> > >> >> > }
>> > >> >>
>> > >> >>
>> > >> >>
>> > >>
>> > >>
>> > >>
>> >
>> >
>> >


Jul 21 '05 #12

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

Similar topics

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...
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...
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...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.