By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,827 Members | 2,155 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,827 IT Pros & Developers. It's quick & easy.

Accessing Array Items after Response.Redirect

P: n/a
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
Share this Question
Share on Google+
11 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.