比如在button1的点击事件里会有一个变量a,我如何在button2的点击事件里获得button1的变量a的值?

解决方案 »

  1.   

    使用 ViewState 保存起来。
      

  2.   

    哥们给个事例代码看看OK吗?
    比如 a.text = b.text
    来个简单易懂的
      

  3.   

    string strGlobal;Button1_Click()
    {
        ViewState["value"] = a;//用ViewState
        Session["Value"] = a;  //用Session
        Response.Redirect("thisPage.aspx?a="+ a);
        strGlobal = a;
    }Button2_Click()
    {
        string strViewState = ViewState["value"].ToString();
        string strSession = Session["Value"].ToString();
        string strQueryString = Request.QueryString["a"].ToString();
        string strGlobal = strGlobal;
    }这四种都可以。
      

  4.   

    还可以这样:Button1_Click()
    {
        Button2.CommandName = a;
    }Button2_Click()
    {
        string str = Button2.CommandName;
    }
      

  5.   

    private void button1_click(object sender, System.EventArgs e)
    {
    ViewState["test"]=xxx;
    }
    private void button2_click(object sender, System.EventArgs e)
    {
    yyy=ViewState["test"].ToString();
    }
      

  6.   

    ViewState 有没有存储空间限制?
    strGlobal  这个是怎么用的? 我用的是VB.NET 我public了一个变量无法使用.
      

  7.   

    1 - ViewState 有没有存储空间限制?
    2 - strGlobal  这个是怎么用的? 我用的是VB.NET 我public了一个变量无法使用.答:
    1 - 内存有多大,ViewState 就有多大。
    2 - 我是用C#的,VB 可能是 public Dim strGlobal AS String