Innova
Innova

Reputation: 4971

button click save in session

i have two buttons . view and viewdaywise.

i need to know which button is clicked right now.

how to store that in session / or any other choice???

Upvotes: 1

Views: 1890

Answers (1)

djdd87
djdd87

Reputation: 68476

You cannot store the Button as it's non-serializable, however you can store the ID of button:

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

Then to retrieve the button, you can do something along the lines of the following:

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

Upvotes: 1

Related Questions