Web - Pressing "Return" on a form

D

David P. Donahue

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
(e-mail address removed)
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top