从另一个事件调用变量

时间:2009-09-20 03:54:33

标签: c# asp.net

我想从另一个事件调用变量,例如

     public void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {

        var ccc = lblTicketsA;
    }

 public void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
             ccc.text = "test";


        }

        catch (Exception ex)
        {
            lblDisplay.Text = ex.Message;
        }
    }

谢谢

1 个答案:

答案 0 :(得分:3)

使ccc像这样的实例字段:

private SomeType ccc;

public void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    this.ccc = lblTicketsA;
}

public void btnSubmit_Click(object sender, EventArgs e)
{
    try
    {
        this.ccc.text = "test"
    }
    catch (Exception ex)
    {
        lblDisplay.Text = ex.Message;
    }
}