views:

20

answers:

3

Working with asp.net, and I am trying to find a way to change default ENTER key press target on client side. Based on something like the currently focused div or input.

the target would be asp.net button controls with postback event.

Looking for solution for both IE and Firefox.

I am also using "WebForm_FireDefaultButton(event, controlId)" trying to set the default button but it doesn't work for Firefox; work fine for IE thou.

thanks

A: 

Look at the Default Button property of an ASP.NET Panel Control

bechbd
trying to set everything on the client side.
Eatdoku
In that case you will need to look at something like this: http://www.devx.com/vb2themax/Tip/18846
bechbd
A: 

It's too difficult to answer this question without knowing the context. Generally speaking you must prepare javascript with required actions and then add something like

onkeydown = "if (event.keyCode == 13) submitForm(); if (event.keyCode == 27) cancelLogin();"

on client side or something similar on server side to action producing controls. The above example refers to MVC. For WebForms you can use __doPostBack instead of my submitForm() function (link text). Usually I used such scenario with inputs (TextBox controls for WebForms).

ILog
that's actually what I did, i call __doPostBack(control, '') but on the server side it does not going into the event handler. But if i click on the button it would work correctly. The capturing of the enter key work fine.
Eatdoku
That might be because of complex naming of controls. Did you use it like this __doPostBack('<%= btnSignIn.UniqueID %>', ''); ?
ILog
A: 

here is the cause and solution i just found Asp.Net Form DefaultButton Error in Firefox

basically, on whatever event you prefer, call the following "FireDefaultButton" function to set the default fire button. The out of box function "WebForm_FireDefaultButton" does not compatible with Firefox (see the link for detail)

function FireDefaultButton(event, target) 
{
// srcElement is for IE
var element = event.target || event.srcElement;

if (13 == event.keyCode && !(element && "textarea" == element.tagName.toLowerCase())) 
{
    var defaultButton;
    defaultButton = document.getElementById(target);

    if (defaultButton && "undefined" != typeof defaultButton.click) 
    {
        defaultButton.click();
        event.cancelBubble = true;
        if (event.stopPropagation) 
            event.stopPropagation();
        return false;
    }
}
return true;
}
Eatdoku