2010-06-24 128 views

回答

1

不能保存按鈕,因爲它是不可序列,但你可以存儲按鈕的ID:

private void LogLastButton(Button button) 
{ 
    Session["LastButtonId"] = button.ID; 
} 

protected void ButtonView_Click(object sender, EventArgs e) 
{ 
    this.LogLastButton((Button)sender); 
} 

protected void ButtonViewDayWise_Click(object sender, EventArgs e) 
{ 
    this.LogLastButton((Button)sender); 
} 

然後檢索按鈕,你可以沿着以下的線路做一些事情:

Button lastButton = Page.Controls.Find(Session["LastButtonId"].ToString()); 
+0

我會用ViewState來代替Session。 – bloparod 2010-06-25 03:16:58