2012-01-10 15 views
0

私は背後に、次のコードを持っている:あるページから別のページにパラメータを渡すにはどうすればよいですか?

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

私は別のASPX.CSファイルに配置ラベルのイベントにbtn.CommandArgumentのコンテンツを渡したいです。 これを実装する方法はありますか? ありがとうございます!

+1

上のQueryStringを読んで、他のページにパラメータを渡す方法の多くは、GET経由で送信し、そこにありますメソッド "?param = value&param2 = value2"などを使用したり、セッションオブジェクトまたはアプリケーションオブジェクトに格納したり、静的クラス/オブジェクトを使用してページから渡すパラメータを格納することさえできます。実装は基本的には、作業するアプリケーションのアーキテクチャに依存します。 – Afshin

+0

クロスページの投稿がオプションの場合は、次のページをご覧ください:http://stackoverflow.com/questions/8747946/what-is-the-best-method-to-retrieve-the-post-value-on-another -page-in-asp-net-4/8748657#8748657 –

答えて

0

QueryStringsを使用できます。あなたのsomepage.aspxに、あなたが持つことができ、その後

string url = String.Format("http://www.example.com/somepage.aspx?labeltext={0}",btn.CommandArgument); 

//"labeltext" is the same name we used above as the ID 
string lblText = Request.QueryString["labeltext"]; 
if (lblText != null) 
{ 
    myLabel.Text = lblText; 
} 

をテキストはURLに渡すのに適しないかもしれないという可能性がある場合たとえば、あなたのURLは次のように見ることができますHttpServerUtility.UrlEncodeでエンコードし、 HttpServerUtility.UrlDecodeでデコードしてから、ラベルに割り当てることができます。

1

セッションを使用する必要があります。セッションに値を入れ、別のページでそれを読んでください。

Session["key"]=value; 
0

そのため、クエリ文字列を使用します。

Response.Redirect("AnotherPage.aspx?CommandArgument=SomeArgument"); 

その後もAnotherPage.aspx

string commArgument = Request.QueryString["CommandArgument"]; 
関連する問題