David C
asked on
ASP.NET defaultbutton not working in Chrome and Firefox
Hi Experts, I have the code as below. I had been using this, since asp:panels were not working so I tried this and still cant get it to work. Can anybody point me in the right direction.
'function in root
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;
}
'.aspx.vb
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ClientScript.RegisterClientScriptInclude("FixFireDefault", "FireDefaultButtonFix.js")
End Sub
'.aspx
<div onkeypress="return FireDefaultButton(event, '<%= LinkButton1.ClientID %>')">
table with controls
</div>
Quite weird that asp:panel is not accepting defaultbutton
If you want it for the full page then you can use this code
Page.Form.DefaultButton = Button1.ClientID;
If you insist on using JS try this link
http://www.devx.com/vb2themax/Tip/18846
If you want it for the full page then you can use this code
Page.Form.DefaultButton = Button1.ClientID;
If you insist on using JS try this link
http://www.devx.com/vb2themax/Tip/18846
ASKER
@Conceptinfotech - the code is not working
@masterpass - Page.Form.DefaultButton = LinkButton1.ClientID works when the page loads i.e. I can see the LinkButton being given focus and if I press enter at that time the code is executed, but as soon as I click into the textbox etc. it loses the focus then when I press enter nothing happens again.
@masterpass - Page.Form.DefaultButton = LinkButton1.ClientID works when the page loads i.e. I can see the LinkButton being given focus and if I press enter at that time the code is executed, but as soon as I click into the textbox etc. it loses the focus then when I press enter nothing happens again.
Type something into the textbox and then try pressing enter. I think it will work then
ASKER
Thats what I mean. In chrome when the linkbutton has focus it is highlighted by an orange border when I put in the username and password that orange border dissapears. When I press enter, nothing happens
ASKER
The Experts Exchange website uses aspx and pressing enter during logon works in Chrome,Firefox etc. Can they help !!!
ASKER
hi guys I've got all browsers to recognise the enter key being pressed but I cant call the function that handles the login in my aspx.vb. How do I call a function for example login()
<script type="text/javascript">
function CheckKeyPress(key) {
if (key == 13) {
alert("Enter key pressed");
return false;
}
}
</script>
<asp:TextBox ID="TextBox2" runat="server" TextMode="Password" onkeydown="return CheckKeyPress(event.keyCode);"></asp:TextBox>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In your Javasript function when u are taking value in "defaultbutton"... plz try this code
if (__nonMSDOMBrowser) {
defaultButton = document.getElementById(ta
}
else {
defaultButton = document.all[target];
}
best of luck