I understand the ASP.net Page Life Cycle, I get that when I click a button, it first reloads the page then it executes the code behind for my button. My question is how do I get it so that I can set something before this process happens. I am trying to pass a variable that the button has been clicked, but because of the page life cycle it never receives this. What can I do so that I can determine that this button has been clicked maybe I am over-thinking this, or even under-thinking.
Page Load:
ImageButton btn = (ImageButton)(Page.FindControl("displayYImgBtn"));
if (btn != null)
{
string state = btn.CommandArgument;
if (state == "true")
{
search();
btn.CommandArgument = "false";
}
}
Button:
ImageButton btn = (ImageButton)(sender);
btn.CommandArgument = "true";
You could always inspect the post variables directly. If your submit button was clicked, it will have a value in the
Request.Formcollection, if it’s not postback or some other control caused postback, it shouldn’t appear.