Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1387
  • Last Modified:

ASP.NET default button property does not work in FireFox

In ASP.NET there is a property of the <asp:panel> control called default button.  If an element within that panel control has the focus at the time the enter button is clicked by the user, then the control with the id specified by the defualt button property of the control is triggered.  The ASP.NET syntax looks as follows...

<asp:Panel runat="server" ID="pnlNewContact" CssClass="addContactPanel" DefaultButton="lbAddNewContact">
...
...
...
</asp:Panel>

This seems to work fine in IE, but it is not working in FireFox.  This is something very damaging to the page I'm working on as the alternate defualt button that is selected by no doing of my own is a delete button.

Is there any way to make this work in FireFox?  Or some other way to control the event that is fired when the enter button is clicked.

0
josephdaviskcrm
Asked:
josephdaviskcrm
  • 5
  • 2
1 Solution
 
copyPasteGhostCommented:
javascript:

function clickButton(e, buttonid) {
            var evt = e ? e : window.event;
            var bt = document.getElementById(buttonid);
            if (bt) {
                if (evt.keyCode == 13) {
                    bt.click();
                    return false;
                }
            }
        }


C#

txtTextBox.Attributes.Add("onkeypress", "return clickButton(event,'" + btnToSubmitPage.ClientID + "')");

That should work.
0
 
josephdaviskcrmAuthor Commented:
I'm not sure I'm totally following you.  If this function were to be added to the keypress event in the aspx file, how would it look?

Also, I'm wondering if this can be added to buttons instead of to a text box so that I can program into the button to test and see if it was triggered by an enter click and if so to do nothing.
0
 
copyPasteGhostCommented:
<script language="javascript" type="text/javascript">
function clickButton(e, buttonid) {
            var evt = e ? e : window.event;
            var bt = document.getElementById(buttonid);
            if (bt) {
                if (evt.keyCode == 13) {
                    bt.click();
                    return false;
                }
            }
        }
</script>
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
copyPasteGhostCommented:
yes it can give it a shot. let me know if there are any problems.
0
 
josephdaviskcrmAuthor Commented:
So does the return false cancel out the submit functionality?  Or what exactly needs to happen here?  I have multiple buttons on my page that act as instant delete buttons for the records they correspond to.  I don't want them ever to be activated by the enter key press event.  Here is the function that is called when any of these is clicked...

function DeleteContact(Email) {
        var xmlHttpObj = CreateXmlHttpRequestObject();
        xmlHttpObj.onreadystatechange = function() {
            if (xmlHttpObj.readyState == 4) {
                UpdateAddressBook()
            }
        }
        xmlHttpObj.open("GET", "CustomAjaxResponse.aspx?AR=DeleteContact&contact=" + Email + "&r=" + (Math.random() * 9999999), true);
        xmlHttpObj.send(null);
        return false;
    }

So how would I encorporate your function into this one?
0
 
copyPasteGhostCommented:
if you just want to stop the enter key from sumbitting buttons you can put this at the top of your page.

<script language="javascript" type="text/javascript">
function noEnter(e) {
          var evt = e ? e : window.event;
          if (evt.keyCode == 13) {
             return false;
          }
       }
0
 
copyPasteGhostCommented:
</script>

ANd then in your code behind...

btn1.Attributes.Add("onkeypress", "return noEnter()");
btn2.Attributes.Add("onkeypress", "return noEnter()");
btn3.Attributes.Add("onkeypress", "return noEnter()");
btn4.Attributes.Add("onkeypress", "return noEnter()");

Ghost
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now