![](/img/trans.png)
[英]How to pass query string parameters from one page and get in another in WP 7 using MVVM Light
[英]How to pass parameters from one page to another?
我后面有以下代碼:
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();
}
}
我想將btn.CommandArgument的內容傳遞給放置在另一個ASPX.CS文件中的Label事件。 有什么辦法可以實現呢? 先感謝您!
您需要使用會話。 將值放入會話,然后在另一頁中讀取它。
Session["key"]=value;
您可以使用QueryStrings 。 例如,您的網址將如下所示:
string url = String.Format("http://www.example.com/somepage.aspx?labeltext={0}",btn.CommandArgument);
然后,在somepage.aspx
,您可以擁有:
//"labeltext" is the same name we used above as the ID
string lblText = Request.QueryString["labeltext"];
if (lblText != null)
{
myLabel.Text = lblText;
}
如果文本可能不適合傳遞URL,則可以使用HttpServerUtility.UrlEncode對其進行編碼,然后使用HttpServerUtility.UrlDecode對其進行解碼,然后再將其分配給標簽。
為此使用查詢字符串:
Response.Redirect("AnotherPage.aspx?CommandArgument=SomeArgument");
然后閱讀查詢字符串AnotherPage.aspx
string commArgument = Request.QueryString["CommandArgument"];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.