When we set a default button for a page we are getting some strange behaviour in FF. If you are editing a multiline textbox in IE and you press the return key, a carriage return is added to the textbox contents, but if you hit the return key in FF the page
is submitted using the default button. How can we stop this?
I've been messing around with your suggestion and just cannot get anywhere. At the moment I have the following code:
...
Me.TxtMessage.Attributes("OnKeyPress") =
"if (event.keyCode == 13) { if (event.stopPropogation) { event.stopPropogation(); } else { return false; } }"
...
AFAIK this should work but it seems the only way of actually stopping this from happening is to remove the default button alltogether. When we set the default button, we get the following line added to the form declaration:
...
onkeypress="javascript:return WebForm_FireDefaultButton(event, 'ctl00_ContentPlaceHolder1_BtnSubmit')"
...
Not matter what I try, I cannot override this behaviour in FF.
As I said in my earlier post, the javascript that is added to the form's onkeypress when I set the default button seems to be what is causing this issue. If I remove the default button, it removes the javascript and the form works just as expected in FF.
I've also tried your suggestion of clearing the JS console in FF, but when I load it [the console] it is already empty.
Again, thank you for your help. It is much appreciated :)
Something else has to be causing this weird behavior. It doesnt make sense that one of the most popular browsers cant handle a simple html object. So if you post your code Ill take a look at it. Duplicate it and tell you whats wrong.
ANd here is the attached JS file:
-----------------------------------------------------------------------------------------------------------------------------
sroughley
Participant
1404 Points
381 Posts
Enter key press in multiline textbox causing postback in FF.
Jul 16, 2007 09:19 AM|LINK
Hi all,
When we set a default button for a page we are getting some strange behaviour in FF. If you are editing a multiline textbox in IE and you press the return key, a carriage return is added to the textbox contents, but if you hit the return key in FF the page is submitted using the default button. How can we stop this?
Regards,
Stephen.
triggered
Contributor
3356 Points
908 Posts
Re: Enter key press in multiline textbox causing postback in FF.
Jul 16, 2007 07:06 PM|LINK
Stephen,
doesnt sound right, the enter key should only trigger the button if focus is outside the textarea. Play around with
mytextbox.value.keyCode == '13'
where this is the textbox
sroughley
Participant
1404 Points
381 Posts
Re: Enter key press in multiline textbox causing postback in FF.
Jul 17, 2007 10:46 AM|LINK
Thanks for the reply.
I've been messing around with your suggestion and just cannot get anywhere. At the moment I have the following code:
...
Me.TxtMessage.Attributes("OnKeyPress") = "if (event.keyCode == 13) { if (event.stopPropogation) { event.stopPropogation(); } else { return false; } }"
...
AFAIK this should work but it seems the only way of actually stopping this from happening is to remove the default button alltogether. When we set the default button, we get the following line added to the form declaration:
...
onkeypress="javascript:return WebForm_FireDefaultButton(event, 'ctl00_ContentPlaceHolder1_BtnSubmit')"
...
Not matter what I try, I cannot override this behaviour in FF.
Regards,
Stephen.
triggered
Contributor
3356 Points
908 Posts
Re: Enter key press in multiline textbox causing postback in FF.
Jul 17, 2007 02:19 PM|LINK
You should try the following:
1. change OnKeyPress to onkeypress, it is defined at the DOM level as onkeypress.
2. txtBox.Attributes.Add("onkeypress","return StopPropogation(event,this)");
function StopPropogation(e,objTextArea)
{
if(e.keyCode == "13")
{
objTextArea.value += objTextArea.value + '\n';
return false;
}
return true;
}
I hope this works for you.
sroughley
Participant
1404 Points
381 Posts
Re: Enter key press in multiline textbox causing postback in FF.
Jul 18, 2007 03:56 PM|LINK
Thanks for your help. I gave your code a try (including the lower case attribute name) and it still submits the form.
Regards,
Stephen.
triggered
Contributor
3356 Points
908 Posts
Re: Enter key press in multiline textbox causing postback in FF.
Jul 18, 2007 04:07 PM|LINK
Then I would start looking at other areas such as...
most likely you have other javascript written on your page that is causing an error, which means the function I gave you wont run.
Try pulling your page up in Fire Fox, Pull up the javascript console, clear it and then run your page hitting the button and see whats wrong.
sroughley
Participant
1404 Points
381 Posts
Re: Enter key press in multiline textbox causing postback in FF.
Jul 18, 2007 04:18 PM|LINK
As I said in my earlier post, the javascript that is added to the form's onkeypress when I set the default button seems to be what is causing this issue. If I remove the default button, it removes the javascript and the form works just as expected in FF. I've also tried your suggestion of clearing the JS console in FF, but when I load it [the console] it is already empty.
Again, thank you for your help. It is much appreciated :)
Regards,
Stephen.
triggered
Contributor
3356 Points
908 Posts
Re: Enter key press in multiline textbox causing postback in FF.
Jul 18, 2007 04:38 PM|LINK
Something else has to be causing this weird behavior. It doesnt make sense that one of the most popular browsers cant handle a simple html object. So if you post your code Ill take a look at it. Duplicate it and tell you whats wrong.
sroughley
Participant
1404 Points
381 Posts
Re: Enter key press in multiline textbox causing postback in FF.
Jul 18, 2007 05:21 PM|LINK
Will do! It'll be in the morning though as its near supper time and I need to get home at some point tonight. :)
Thanks!
Stephen.
sroughley
Participant
1404 Points
381 Posts
Re: Enter key press in multiline textbox causing postback in FF.
Jul 19, 2007 09:30 AM|LINK
Here's the generated page code:
-----------------------------------------------------------------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb"> <head id="ctl00_Head1" profile="http://gmpg.org/xfn/11"> <title> CompanyName.co.uk - Contact Us </title> <link rel="shortcut icon" href="lib/img/icon/favorite.png" type="image/png" /> <link rel="start" href="http://www.CompanyName.co.uk/" /> <link rel="stylesheet" href="lib/css/ocm.v1.1.css" type="text/css" media="screen,projection,tv" /> <meta http-equiv="content-language" content="en-gb" /> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta http-equiv="imagetoolbar" content="no" /> <meta name="author" content="" /> <meta name="description" content="CompanyName.co.uk - Buy and Sell Your House Online Commision Free" /> <meta name="doc-class" content="living document" /> <meta name="generator" content="" /> <meta name="keywords" content="CompanyName" /> <meta name="mssmarttagspreventparsing" content="true" /> <meta name="rating" content="general" /> <meta name="revisit-after" content="5 days" /> <meta name="robots" content="index, follow" /> <script src="lib/js/functs.js" type="text/javascript"></script> </head> <body> <form name="aspnetForm" method="post" action="Contact.aspx" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'ctl00_ContentPlaceHolder1_BtnSubmit')" id="aspnetForm"> <div> <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /> <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="" /> </div> <script type="text/javascript"> <!-- var theForm = document.forms['aspnetForm']; if (!theForm) { theForm = document.aspnetForm; } function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } } // --> </script> <script src="/WebResource.axd?d=nlLoPFvybCe5rWYmf1jtaw2&t=633197740010000000" type="text/javascript"></script> <script src="/ScriptResource.axd?d=JaZCC2QXlwiQB_Am8UaPJfvgzw54YBhk5MRswM6QSxUl4vem0fTxdyHHoa9RqrNiqMbK2gKrp2LKq2uUSq3ZstNEQDx-SDv1svo7hjX6xrY1&t=633177704208281250" type="text/javascript"></script> <script src="/ScriptResource.axd?d=JaZCC2QXlwiQB_Am8UaPJfvgzw54YBhk5MRswM6QSxUl4vem0fTxdyHHoa9RqrNiqMbK2gKrp2LKq2uUSq3Zsn1acA8lIFLGNC6jtAN3BhlGtjWbKdGMdCn07owdV85u0&t=633177704208281250" type="text/javascript"></script> <script type="text/javascript"> //<![CDATA[ Sys.WebForms.PageRequestManager._initialize('ctl00$ScriptManager1', document.getElementById('aspnetForm')); Sys.WebForms.PageRequestManager.getInstance()._updateControls([], [], [], 90); //]]> </script> <div id="wrapper"> <div id="header"> <h1><a href="Default.aspx"><img src="lib/img/CompanyName.png" alt="CompanyName.co.uk" title="CompanyName.co.uk" height="93" width="270" id="IMG1" onclick="return IMG1_onclick()" /></a></h1> <!-- BEGIN MAIN NAVIGATION --> <ul> <li><a href="Default.aspx"><span class="sliding_door">Home</span></a></li> <li><a href="About.aspx"><span class="sliding_door">About</span></a></li> <li><a href="Faq.aspx"><span class="sliding_door"><acronym title="Frequently Asked Questions">FAQ</acronym></span></a></li> <li><a href="Contact.aspx" class="current"><span class="sliding_door">Contact</span></a></li> <li><a href="Seller/Members.aspx"><span class="sliding_door">Your Account</span></a></li> </ul> <!-- END MAIN NAVIGATION --> <div class="clear"></div> </div> <div id="content"> <h2>Contact Us</h2> <div class="content_left half_column"> <p>If you want to get in touch with CompanyName.co.uk for any reason then you're in the right place!</p> <p>CompanyName looks forward to hearing from you!</p> </div> <div class="content_right half_column"> <div id="contact_form"> <fieldset> <legend>Contact us</legend> <p><label for="ctl00_ContentPlaceHolder1_TxtName" id="ctl00_ContentPlaceHolder1_LblName">Name</label><br /> <input name="ctl00$ContentPlaceHolder1$TxtName" type="text" id="ctl00_ContentPlaceHolder1_TxtName" class="required text_input" /></p> <p><label for="ctl00_ContentPlaceHolder1_TxtEmail" id="ctl00_ContentPlaceHolder1_LblEmail">Email Address</label><br /> <input name="ctl00$ContentPlaceHolder1$TxtEmail" type="text" id="ctl00_ContentPlaceHolder1_TxtEmail" class="required text_input" /></p> <p><label for="ctl00_ContentPlaceHolder1_TxtTelephone" id="ctl00_ContentPlaceHolder1_LblTelephone">Telephone Number</label><br /> <input name="ctl00$ContentPlaceHolder1$TxtTelephone" type="text" id="ctl00_ContentPlaceHolder1_TxtTelephone" class="required text_input" /></p> <p><label for="ctl00_ContentPlaceHolder1_TxtMessage" id="ctl00_ContentPlaceHolder1_LblMessage">Your Message</label><br /> <textarea name="ctl00$ContentPlaceHolder1$TxtMessage" rows="7" cols="31" id="ctl00_ContentPlaceHolder1_TxtMessage" class="required text_input" onkeypress="return StopPropogation(event, this);"></textarea></p> <p><label for="ctl00_ContentPlaceHolder1_TxtCaptchaInput" id="ctl00_ContentPlaceHolder1_LblCaptchaInput">Anti-spam Verification</label><br /> <img id="ctl00_ContentPlaceHolder1_ImgCaptcha" src="lib/img/captcha/6527e058-7a43-48aa-a742-4951f9131adb.jpg" alt="CAPTCHA generated image, please contact for assistance" style="border-width:0px;" /><br /> What are the numbers in the image?<br /> <input name="ctl00$ContentPlaceHolder1$TxtCaptchaInput" type="text" id="ctl00_ContentPlaceHolder1_TxtCaptchaInput" class="required validate-alphanum captcha" /></p> </fieldset> <p class="right"><input type="submit" name="ctl00$ContentPlaceHolder1$BtnSubmit" value="Submit" id="ctl00_ContentPlaceHolder1_BtnSubmit" class="submit" /></p> </div> </div> <div class="clear"> </div> </div> <div id="footer"> <p> <a href="./">CompanyName.co.uk</a> is a trading name of Company Name <acronym title="Limited">Ltd</acronym>. Registered in England and Wales No. xxxxxx </p> <p> <acronym title="Telephone">Tel</acronym>: xxxxx xxxxxx. </p> </div> </div> <div id="shadow_top" class="chrome_shadow"> </div> <div id="shadow_bottom" class="chrome_shadow"> </div> <div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBwLBpeGaCwLU9MeCAgL0z6y4BgL60bWTDALxooSZDQKyzZeUDwLY7aXMBA1jxXN7+QcfaoFo4u4QY7eBke/L" /> </div> <script type="text/javascript"> <!-- Sys.Application.initialize(); // --> </script> </form> </body> </html>
-----------------------------------------------------------------------------------------------------------------------------
ANd here is the attached JS file:
-----------------------------------------------------------------------------------------------------------------------------