I assume that you are looking for something like pressing the enter key
should fire a button click even other than the default button.
if my assumption is correct then the answer is in a simple client-side
javascript function called whenever a button is pressed, that, if the button
pressed is the Enter key, cancels the default submit and simulates a click on
the wanted button. Here's the function, that you can copy and paste as-is
into your ASPX pages, or that you can paste into a separate .js file,
referenced by any ASPX page that needs it:
< language="javascript">
function KeyDownHandler(btn)
{
// process only the Enter key
if (event.keyCode == 13)
{
// cancel the default submit
event.returnValue=false;
event.cancel = true;
// submit the form by programmatically clicking the specified button
btn.click();
}
}
< /script>
Now, in the input controls declaration you just have to call this function
when a button is pressed, by handling the onKeyPressed client-side event, and
pass a reference to the default button:
< runat="server" id="FN" onkeydown= "KeyDownHandler(DefButton)">
--
Kannan.V
Home :
http://www.kannanv.com
Blog :
http://kannanv.blogspot.com
Web :
http://www.DotnetLounge.net
"Any one who has never made a mistake has never tried anything new" - Einstein
"getdotnet" wrote:
hello,
I am using a form which has multiple buttons(asp server controls) say B1, B2
and B3. The postabck gets fired on B1 click whereas I want it to happen on B3
click. I know that by default the first button on a page is set as the
'submit' button and that is the reason for this behaviour.
Now teh question is, how can i prevent postback firing on B1 click and force
it to fire on B3 click. i heard asp.net has a simple way to handle this and
there is no need to write a _dopostback javascript function.
Can somebody help me on this?
Thanks