By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,723 Members | 1,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,723 IT Pros & Developers. It's quick & easy.

Web - Pressing "Return" on a form

P: n/a
Is there a way to specify on each control of a page which button on the
page should be "clicked" when the user presses "return" from within that
control? It seems like it's always just defaulting to the first button
it finds on the page, which isn't always correct.
Regards,
David P. Donahue
dd******@ccs.neu.edu
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
hi david,

Following is what you can do to set the focus to the desired button. It is
necessary to set the focus in the click event
of the button.
I have used RegisterStartupScript to register the javascript. Copy paste the
following code in the webform class and create the controls as necessary.

protected void setTheFocus( System.Web.UI.Control btnControl )
{
string s = "<SCRIPT language='javascript'>document.getElementById('" +
btnControl.ID + "').focus() </SCRIPT>";
this.RegisterStartupScript( "FocusEvent", s );
}

private void Button1_Click(object sender, System.EventArgs e)
{
this.setTheFocus(Button1);
}

private void Button2_Click(object sender, System.EventArgs e)
{
this.setTheFocus(Button2);
}
Happy programming!!!

pradeep_TP

"David P. Donahue" wrote:
Is there a way to specify on each control of a page which button on the
page should be "clicked" when the user presses "return" from within that
control? It seems like it's always just defaulting to the first button
it finds on the page, which isn't always correct.
Regards,
David P. Donahue
dd******@ccs.neu.edu

Nov 16 '05 #2

P: n/a
Here's a control/sample that will solve your problem.

http://scottwater.com/articles/DefaultTextBoxControl

HTH

Dale Preston
MCAD, MCDBA, MCSE
"David P. Donahue" <dd******@ccs.neu.edu> wrote in message
news:uv*************@TK2MSFTNGP14.phx.gbl...
Is there a way to specify on each control of a page which button on the
page should be "clicked" when the user presses "return" from within that
control? It seems like it's always just defaulting to the first button
it finds on the page, which isn't always correct.
Regards,
David P. Donahue
dd******@ccs.neu.edu

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.