如何将参数从一页传递到另一页? [英] How to pass parameters from one page to another?
问题描述
您好,在按A页上的确定按钮时,在B页上出现了确定的标题.
例如:
我按下页面A上的"MenCollectionOptic"按钮,在页面B的Label控件中获得"MenCollectionOptic"文本标题.
(或)
按下页面A上的"WomenCollectionSun"按钮,在页面B上的Label控件中获得"WomenCollectionSun"文本标题.
这是我在A页中的ASP代码:
Hello,on pushing determined button on the page A, appeared determined title on page B.
For Example:
I press button "MenCollectionOptic" on page A, i get "MenCollectionOptic" text title in Label control,on page B.
(or)
I press button "WomenCollectionSun" on page A, i get "WomenCollectionSun" text title in Label control,on page B.
Here is my ASP code in page A:
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Repeater ID="rpt1" runat="server" onitemdatabound="rpt1_ItemDataBound"
onitemcommand="rpt1_ItemCommand">
<ItemTemplate>
<div><%# Eval("Name") %>-<%# Eval("CollectionType")%><asp:Button ID="btn1" runat="server" Text="edit item" PostBackUrl="~/B.aspx" EnableViewState="True"/>
</div>
<br />
</ItemTemplate>
</asp:Repeater>
<br />
Here is the code behinde:
<pre lang="c#">
public partial class _Default : System.Web.UI.Page
{
List<GlassesCollection> gc= BL.Example.GetCategory() ;
protected void Page_Load(object sender, EventArgs e)
{
rpt1.DataSource = gc;
rpt1.DataBind();
}
protected void rpt1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
Button btn = (Button)e.Item.FindControl("btn1");
btn.CommandArgument = DataBinder.Eval(e.Item.DataItem,"CollectionID").ToString();
}
}
我的想法是,页面B后面的代码获取选定的collectionID,并在Label事件中使用它来显示适当的标题.
我的问题是,如何才能将collectionID从后面的A页代码传递到后面的B页代码?
My idea is that code behind of page B gets the chosen collectionID and use it in Label''s event to display appreate colletion title.
My quiestion is how can collectionID can be passed from page A code behind to page B code behind?
Thank you in advance!
推荐答案
您可以通过两种方式解决此问题-1)使用表单参数,或2)使用会话.
You can solve this problem in 2 ways - 1) Use of form parameters, or 2)Use session.
HI,
如果您直接重定向到页面B,则可以使用查询字符串将值传递到页面A到页面B
如
这在A页中
If you are directly redirected to page B You can use query string to pass your values to Page A to Page B
as
this is in page A
Response.Redirect("pageB.aspx?collectionID ="+ yourvalue+" );
在B页:
您可以通过
检索collectionID值
in Page B:
You can retrive collectionID value by
Request.QueryString[0];
或
or
Request.QueryString["collectionID "]
问候,
Pal
Regards,
Pal
在第2页中用于捕获第1页中所需的所有数据,请创建一个构造函数,然后在page1中为page2的类创建obj并通过它发送.类似这样的东西
in page 2 for capturing all the data you want from page 1 create a constructor and in page1 create obj for page2 s class and send through it.some thing like this
/////////////////////page1
class page1class{
//pass your objects
page2class obj = new page2class(MenCollectionOptic.text,WomenCollectionSun.text)
}
//////////////////page2
class page2class{
//constructor
void page2class(string MenCollectionOptic,string WomenCollectionSun )
{
this.MenCollectionOptic=MenCollectionOptic;
this.WomenCollectionSun= WomenCollectionSun;
}
这篇关于如何将参数从一页传递到另一页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!