在Response.Redirect之后访问数组项 [英] Accessing Array Items after Response.Redirect

查看:65
本文介绍了在Response.Redirect之后访问数组项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人可以帮助我进行网络应用程序设计

问题。我有一个aspx页面,它构建了一个名为address

的arraylist,并将arraylist项中的值输出到datagrid。我正在使用

viewstate对象在回发页面上存储Arraylist项目。


我的问题是我需要将用户重定向到新的aspx页面和

这个新页面我需要能够访问我的arraylist中的项目。这是

不使用会话对象吗?当

页面被重定向时,viewstate是否会丢失?下面是用于创建我的arraylist的代码和

将其存储在viewstate中。我可以使用Server.Transfer来做到这一点吗?如果是的话

推荐?

有没有一种简单的方法可以做到这一点我可以忽略?


谢谢对于迄今为止帮助过我的每个人,感谢任何能够给我建议或者现在帮助我的人。


使用以下内容添加到arraylist的项目文本框。然后绑定到

数据网格。


protected void cmdExcAdrContinue_Click(object sender,System.EventArgs e)

{

ArrayList地址;

地址=(ArrayList)ViewState ["地址"];


地址newAddress = new Address(); < br $>
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 ["地址"] =地址;


this.dgSearchAddresses.DataSource =地址;

this.dgSearchAddresses。 DataBind();


//清理文本框

this.txtAddress1.Text ="" ;;

this .tx tAddress2.Text ="";

this.txtAddress3.Text ="" ;;

this.txtAddress4.Text ="" ;;

this.txtAddress5.Text ="";

this.txtAddress6.Text ="" ;;


}


使用另一个datagrid的内容添加到arraylist。然后他们被保存

来陈述并绑定到我的数据网格。


private void dgResults_ItemCommand(对象来源,

System.Web .UI.WebControls.DataGridCommandEventArgs e)

{

地址a =新地址();

数组列表地址;

addresses =(ArrayList)ViewState [" Addresses"];

a.Address1 = e.Item.Cells [0] .Text;

addresses.Add( a);

dgSearchAddresses.DataSource =地址;

dgSearchAddresses.DataBind();

checkArrayList();

}


这是页面加载事件,它使我的页面能够在

帖子之间保持状态并构建arraylist。


private void Page_Load(object sender,System.EventArgs e)

{

ArrayList地址;


//首次加载页面时

if(!IsPostBack)

{

addresses = new ArrayList();

ViewState [" Addresses&qu ot;] =地址;

}

//在随后的PostBacks上:

else

{

addresses =(ArrayList)ViewState [" Addresses"];

if(addresses!= null)

{

this.dgSearchAddresses.DataSource = addresses;

this.dgSearchAddresses.DataBind();

}

}


}


这是我使用的地址类。


[可序列化]

public class Address

{

private string _address1;

public string Address1

{

get {return _address1; }

set {_address1 = value; }

}

私人字符串_address2;

公共字符串地址2

{

get {return _address2; }

set {_address2 = value; }

}

等等............


//私有字符串_fulladdress ;

公共字符串FullAddress

{

get

{

return _address1 + " " + _address2 +" " + _address3 +" " + _address4 +"

+ _address5 +" " + _address6;

}

}

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

推荐答案

有一种很酷的方式(是的, Server.Transfer你可以并将使用):

在与

ArrayList相同的类中定义一个只读公共/内部属性

暴露这个ArrayList(必须至少是模块全局),例如:

public ArrayList List

{

get

{

返回_list;

}

}


从你想去的地方去要重定向到第二页,添加简单的



(其中WebForm2.aspx是您的目的地):

Server.Transfer(" ; WebForm2.aspx");


转到WebForm2.aspx.cs,到你想要从

" WebForm1"中检索ArrayList的地方。并添加此代码以获取它:


WebForm1 webForm1 = base.Context.Handler as WebForm1;

if(null!= webForm1)//对不起, Jon

{

//在这里添加逻辑,例如:

foreach(webForm1.List中的对象o)

{

Response.Write(o.ToString());

}

}


就是这样。


-

问候,

DennisJDMyrén

奥斯陆Kodebureau

" Stephen" <圣***** @ discussions.microsoft.com>在消息中写道

news:59 ********************************** @ microsof t.com ...
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...
我想知道是否有人可以帮助我解决Web应用程序设计问题。我有一个aspx页面,它构建了一个名为address
的arraylist,并将arraylist项中的值输出到datagrid。我正在使用
viewstate对象在回发页面上存储Arraylist项目。

我的问题是我需要将用户重定向到新的aspx页面然后
这个新页面我需要能够访问我的arraylist中的项目。
这个
可以不使用会话对象??当
页面被重定向时,视图状态是否会丢失?下面是用于创建我的arraylist的代码,并将其存储在viewstate中。我可以使用Server.Transfer来做到这一点吗?如果是的话
它建议吗?
是否有一种简单的方法可以做到这一点我可以忽略?

感谢所有帮助过我的人并感谢任何能够给我建议或现在帮助我的人。

使用文本框内容添加到arraylist的项目。然后绑定到
数据网格。

protected void cmdExcAdrContinue_Click(object sender,System.EventArgs e)
{ArrayList addresses;
addresses =(ArrayList )ViewState [" Addresses"];

地址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 ["地址"] =地址;

this.dgSearchAddresses.DataSource =地址;
this.dgSearchAddresses.DataBind();

//清除文本框
this.txtAddress1.Text ="" ;;
this.txtAddress2.Text ="" ;;
this.txtAddr ess3.Text ="";
this.txtAddress4.Text ="" ;;
this.txtAddress5.Text ="" ;;
this.txtAddress6.Text =" ;" ;;



使用另一个数据网格的内容添加到arraylist。然后它们被保存到状态并绑定到我的数据网格。

private void dgResults_ItemCommand(对象源,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
地址a =新地址();
ArrayList地址;
地址=(ArrayList)ViewState ["地址"];
a.Address1 = e.Item.Cells [0] .Text;
addresses.Add(a);
dgSearchAddresses.DataSource = addresses;
dgSearchAddresses.DataBind();
checkArrayList();
}

这是页面加载事件,它使我的页面能够在
帖子之间保持状态并构建arraylist。

private void Page_Load(对象发送者,System.EventArgs e)
{ArrayList地址;

//首次加载页面时
if(!IsPostBack)
{
地址=新的ArrayList();
ViewState ["地址"] =地址;
}
//在后续的PostBacks上:


{
addresses =(ArrayList)ViewState [" Addresses"];
if(addresses!= null)
this.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind ();
}
}


这是我使用的Address类。

[Serializable]
公共类地址
{private string _address1;
public string Address1
{
get {return _address1; }
设置{_address1 = value; }
}
私有字符串_address2;
公共字符串Address2
{
get {return _address2; }
设置{_address2 = value; }
}
等等............
//私有字符串_fulladdress;
公共字符串FullAddress
{
获取
{
返回_address1 +" " + _address2 +" " + _address3 +" " + _address4 +"
"
+ _address5 +" " + _address6;
}
}
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;
}
}



试过这个,但我在浏览器窗口中遇到以下运行时错误

当我运行项目时: -

抛出System.StackOverflowException类型的异常。


你有什么想法吗?非常感谢你的帮助


//点击事件来重定向页面

private void ArrayList_Click(object sender,System.EventArgs e)

{

Server.Transfer(" ArrayListItemsDisplayed.aspx");

}


//添加到我的债务人查询页面(WebForm1)位于顶部

公共ArrayList地址

{

get

{

返回地址;

}

}


//尝试在页面加载时写入值事件

private void Page_Load(object sender,System.EventArgs e)

{

WebForm1 debtor_enquiry = base.Context.Handler as WebForm1;

if(null!= debtor_enquiry)

{

//在这里添加一些逻辑

foreach(object o in debtor_enquiry.addresses)

{

Response.Write(o.ToString());

}

}

}


" Dennis Myr ?? n"写道:
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:
有一种很酷的方式(是的,Server.Transfer你可以并将使用):
在与你的<同一类中定义一个只读公共/内部属性br /> ArrayList
暴露这个ArrayList(必须至少是模块全局),例如:
public ArrayList List
{
get
{
返回_list;
}

转到你要重定向到第二页的地方,添加简单的

(其中WebForm2 .aspx是你的目的地):
Server.Transfer(" WebForm2.aspx");

转到WebForm2.aspx.cs,从哪里想要从WebForm1并添加此代码以获取它:

WebForm1 webForm1 = base.Context.Handler as WebForm1;
if(null!= webForm1)//对不起,Jon
{
在这里添加逻辑,例如:
foreach(webForm1.List中的对象o)
{
Response.Write(o.ToString());
}
}

就是这样。

-
问候,
Dennis JD Myr ?? n
Oslo Kodebureau
斯蒂芬 <圣***** @ discussions.microsoft.com>在消息中写道
新闻:59 ********************************** @ microsof t.com。 ..
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...
我想知道是否有人可以帮助我解决Web应用程序设计问题。我有一个aspx页面,它构建了一个名为address
的arraylist,并将arraylist项中的值输出到datagrid。我正在使用
viewstate对象在回发页面上存储Arraylist项目。

我的问题是我需要将用户重定向到新的aspx页面然后
这个新页面我需要能够访问我的arraylist中的项目。
这个
可以不使用会话对象??当
页面被重定向时,视图状态是否会丢失?下面是用于创建我的arraylist的代码,并将其存储在viewstate中。我可以使用Server.Transfer来做到这一点吗?如果是的话
它建议吗?
是否有一种简单的方法可以做到这一点我可以忽略?

感谢所有帮助过我的人并感谢任何能够给我建议或现在帮助我的人。

使用文本框内容添加到arraylist的项目。然后绑定到
数据网格。

protected void cmdExcAdrContinue_Click(object sender,System.EventArgs e)
{ArrayList addresses;
addresses =(ArrayList )ViewState [" Addresses"];

地址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 ["地址"] =地址;

this.dgSearchAddresses.DataSource =地址;
this.dgSearchAddresses.DataBind();

//清除文本框
this.txtAddress1.Text ="" ;;
this.txtAddress2.Text ="" ;;
this.txtAddr ess3.Text ="";
this.txtAddress4.Text ="" ;;
this.txtAddress5.Text ="" ;;
this.txtAddress6.Text =" ;" ;;



使用另一个数据网格的内容添加到arraylist。然后它们被保存到状态并绑定到我的数据网格。

private void dgResults_ItemCommand(对象源,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
地址a =新地址();
ArrayList地址;
地址=(ArrayList)ViewState ["地址"];
a.Address1 = e.Item.Cells [0] .Text;
addresses.Add(a);
dgSearchAddresses.DataSource = addresses;
dgSearchAddresses.DataBind();
checkArrayList();
}

这是页面加载事件,它使我的页面能够在
帖子之间保持状态并构建arraylist。

private void Page_Load(对象发送者,System.EventArgs e)
{ArrayList地址;

//首次加载页面时
if(!IsPostBack)
{
地址=新的ArrayList();
ViewState ["地址"] =地址;
}
//在后续的PostBacks上:


{
addresses =(ArrayList)ViewState [" Addresses"];
if(addresses!= null)
this.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind ();
}
}


这是我使用的Address类。

[Serializable]
公共类地址
{private string _address1;
public string Address1
{
get {return _address1; }
设置{_address1 = value; }
}
私有字符串_address2;
公共字符串Address2
{
get {return _address2; }
设置{_address2 = value; }
}
等等............
//私有字符串_fulladdress;
公共字符串FullAddress
{
获取
{
返回_address1 +" " + _address2 +" " + _address3 +" " + _address4 +"
"
+ _address5 +" " + _address6;
}
}
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;
}
}




试过这个但是我得到了以下运行时错误我运行项目时浏览器窗口

: -

抛出System.StackOverflowException类型的异常。


你有没有想法?非常感谢你的帮助


//点击事件来重定向页面

private void ArrayList_Click(object sender,System.EventArgs e)

{

Server.Transfer(" ArrayListItemsDisplayed.aspx");

}


//添加到我的债务人查询页面(WebForm1)位于顶部

公共ArrayList地址

{

get

{

返回地址;

}

}


//尝试在页面加载时写入值事件

private void Page_Load(object sender,System.EventArgs e)

{

WebForm1 debtor_enquiry = base.Context.Handler as WebForm1;

if(null!= debtor_enquiry)

{

//在这里添加一些逻辑

foreach(object o in debtor_enquiry.addresses)

{

Response.Write(o.ToString());

}

}

}


" Dennis Myr ?? n"写道:
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:
有一种很酷的方式(是的,Server.Transfer你可以并将使用):
在与你的<同一类中定义一个只读公共/内部属性br /> ArrayList
暴露这个ArrayList(必须至少是模块全局),例如:
public ArrayList List
{
get
{
返回_list;
}

转到你要重定向到第二页的地方,添加简单的

(其中WebForm2 .aspx是你的目的地):
Server.Transfer(" WebForm2.aspx");

转到WebForm2.aspx.cs,从哪里想要从WebForm1并添加此代码以获取它:

WebForm1 webForm1 = base.Context.Handler as WebForm1;
if(null!= webForm1)//对不起,Jon
{
在这里添加逻辑,例如:
foreach(webForm1.List中的对象o)
{
Response.Write(o.ToString());
}
}

就是这样。

-
问候,
Dennis JD Myr ?? n
Oslo Kodebureau
斯蒂芬 <圣***** @ discussions.microsoft.com>在消息中写道
新闻:59 ********************************** @ microsof t.com。 ..
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...
我想知道是否有人可以帮助我解决Web应用程序设计问题。我有一个aspx页面,它构建了一个名为address
的arraylist,并将arraylist项中的值输出到datagrid。我正在使用
viewstate对象在回发页面上存储Arraylist项目。

我的问题是我需要将用户重定向到新的aspx页面然后
这个新页面我需要能够访问我的arraylist中的项目。
这个
可以不使用会话对象??当
页面被重定向时,视图状态是否会丢失?下面是用于创建我的arraylist的代码,并将其存储在viewstate中。我可以使用Server.Transfer来做到这一点吗?如果是的话
它建议吗?
是否有一种简单的方法可以做到这一点我可以忽略?

感谢所有帮助过我的人并感谢任何能够给我建议或现在帮助我的人。

使用文本框内容添加到arraylist的项目。然后绑定到
数据网格。

protected void cmdExcAdrContinue_Click(object sender,System.EventArgs e)
{ArrayList addresses;
addresses =(ArrayList )ViewState [" Addresses"];

地址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 ["地址"] =地址;

this.dgSearchAddresses.DataSource =地址;
this.dgSearchAddresses.DataBind();

//清除文本框
this.txtAddress1.Text ="" ;;
this.txtAddress2.Text ="" ;;
this.txtAddr ess3.Text ="";
this.txtAddress4.Text ="" ;;
this.txtAddress5.Text ="" ;;
this.txtAddress6.Text =" ;" ;;



使用另一个数据网格的内容添加到arraylist。然后它们被保存到状态并绑定到我的数据网格。

private void dgResults_ItemCommand(对象源,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
地址a =新地址();
ArrayList地址;
地址=(ArrayList)ViewState ["地址"];
a.Address1 = e.Item.Cells [0] .Text;
addresses.Add(a);
dgSearchAddresses.DataSource = addresses;
dgSearchAddresses.DataBind();
checkArrayList();
}

这是页面加载事件,它使我的页面能够在
帖子之间保持状态并构建arraylist。

private void Page_Load(对象发送者,System.EventArgs e)
{ArrayList地址;

//首次加载页面时
if(!IsPostBack)
{
地址=新的ArrayList();
ViewState ["地址"] =地址;
}
//在后续的PostBacks上:


{
addresses =(ArrayList)ViewState [" Addresses"];
if(addresses!= null)
this.dgSearchAddresses.DataSource = addresses;
this.dgSearchAddresses.DataBind ();
}
}


这是我使用的Address类。

[Serializable]
公共类地址
{private string _address1;
public string Address1
{
get {return _address1; }
设置{_address1 = value; }
}
私有字符串_address2;
公共字符串Address2
{
get {return _address2; }
设置{_address2 = value; }
}
等等............
//私有字符串_fulladdress;
公共字符串FullAddress
{
获取
{
返回_address1 +" " + _address2 +" " + _address3 +" " + _address4 +"
"
+ _address5 +" " + _address6;
}
}
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;
}
}




这篇关于在Response.Redirect之后访问数组项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆