josephdaviskcrm
asked on
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="lbAddNewCon tact">
...
...
...
</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.
<asp:Panel runat="server" ID="pnlNewContact" CssClass="addContactPanel"
...
...
...
</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.
ASKER
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.
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.
<script language="javascript" type="text/javascript">
function clickButton(e, buttonid) {
var evt = e ? e : window.event;
var bt = document.getElementById(bu ttonid);
if (bt) {
if (evt.keyCode == 13) {
bt.click();
return false;
}
}
}
</script>
function clickButton(e, buttonid) {
var evt = e ? e : window.event;
var bt = document.getElementById(bu
if (bt) {
if (evt.keyCode == 13) {
bt.click();
return false;
}
}
}
</script>
yes it can give it a shot. let me know if there are any problems.
ASKER
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.onreadystatecha nge = function() {
if (xmlHttpObj.readyState == 4) {
UpdateAddressBook()
}
}
xmlHttpObj.open("GET", "CustomAjaxResponse.aspx?A R=DeleteCo ntact&cont act=" + Email + "&r=" + (Math.random() * 9999999), true);
xmlHttpObj.send(null);
return false;
}
So how would I encorporate your function into this one?
function DeleteContact(Email) {
var xmlHttpObj = CreateXmlHttpRequestObject
xmlHttpObj.onreadystatecha
if (xmlHttpObj.readyState == 4) {
UpdateAddressBook()
}
}
xmlHttpObj.open("GET", "CustomAjaxResponse.aspx?A
xmlHttpObj.send(null);
return false;
}
So how would I encorporate your function into this one?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
</script>
ANd then in your code behind...
btn1.Attributes.Add("onkey press", "return noEnter()");
btn2.Attributes.Add("onkey press", "return noEnter()");
btn3.Attributes.Add("onkey press", "return noEnter()");
btn4.Attributes.Add("onkey press", "return noEnter()");
Ghost
ANd then in your code behind...
btn1.Attributes.Add("onkey
btn2.Attributes.Add("onkey
btn3.Attributes.Add("onkey
btn4.Attributes.Add("onkey
Ghost
function clickButton(e, buttonid) {
var evt = e ? e : window.event;
var bt = document.getElementById(bu
if (bt) {
if (evt.keyCode == 13) {
bt.click();
return false;
}
}
}
C#
txtTextBox.Attributes.Add(
That should work.