J
jhoge123
This is one of those problems that should be easy but isn't turning out
that way: There are two textboxes on a page, each associated with a
button which has a Click event to do something different.
What happens when the user presses the Enter key?
I want one of the event handlers to be fired in this situation. The
only solution I have for this is not pretty: To use a flag to check if
the event has been fired from the Page_Load event handler.
bool calledByEnterKey= false;
private void Page_Load(object sender, System.EventArgs e)
{
if(IsPostBack)
{
btnSearch_Click(new Object(), new System.EventArgs());
calledByEnterKey==true;
}
}
This calls my click event for all postbacks. The event then must check
the boolean property calledByEnterKey to make sure it doesn't run
twice:
private void btnSearch_Click(object sender, System.EventArgs e)
{
if (!calledByEnterKey)
{
//do something
}
}
This works, but it's not the clear, elegant solution that I would like.
There must be a better way!
that way: There are two textboxes on a page, each associated with a
button which has a Click event to do something different.
What happens when the user presses the Enter key?
I want one of the event handlers to be fired in this situation. The
only solution I have for this is not pretty: To use a flag to check if
the event has been fired from the Page_Load event handler.
bool calledByEnterKey= false;
private void Page_Load(object sender, System.EventArgs e)
{
if(IsPostBack)
{
btnSearch_Click(new Object(), new System.EventArgs());
calledByEnterKey==true;
}
}
This calls my click event for all postbacks. The event then must check
the boolean property calledByEnterKey to make sure it doesn't run
twice:
private void btnSearch_Click(object sender, System.EventArgs e)
{
if (!calledByEnterKey)
{
//do something
}
}
This works, but it's not the clear, elegant solution that I would like.
There must be a better way!