Welcome Guest Search | Active Topics | Sign In | Register

Exception thrown in FireFox as a result of handling text box enter key Options
P. Chernoch
Posted: Friday, August 22, 2008 9:54:57 AM
Rank: Newbie
Groups: Member

Joined: 8/18/2008
Posts: 9
In my form I have a text box into which the user enters a URL, and two buttons: upload and cancel.
I wanted the upload button to be activated when the user types return while in the text box.

To accomplish this, I followed advice found on a website for handling the enter key:

Code: C#
/*
         * Causes a text box in a form to activate the designated button as its default button on a carriage return
         * in a way that is supported by numerous browsers. 
         * See http://codebetter.com/blogs/darrell.norton/archive/2004/03/03/8374.aspx for commentary.
         */
        public void SetDefaultButton(Page page, TextBox textControl, Button defaultButton)
        {
            // Sets default buttons.
            // Originally created by Janus Kamp Hansen - http://www.kamp-hansen.dk
            // Extended by Darrell Norton - http://dotnetjunkies.com/weblog/darrell.norton/ 
            //   -- added Mozilla support, fixed a few issues, improved performance

            string theScript = @"
<SCRIPT language=""javascript"">
<!--
function fnTrapKD(btn, event){
 if (document.all){
  if (event.keyCode == 13){
   event.returnValue=false;
   event.cancel = true;
   btn.click();
  }
 }
 else if (document.getElementById){
  if (event.which == 13){
   event.returnValue=false;
   event.cancel = true;
   btn.click();
  }
 }
 else if(document.layers){
  if(event.which == 13){
   event.returnValue=false;
   event.cancel = true;
   btn.click();
  }
 }
}
// -->
</SCRIPT>";

            Page.RegisterStartupScript("ForceDefaultToScript", theScript);
            textControl.Attributes.Add("onkeydown", "fnTrapKD(" + defaultButton.ClientID + ",event)");
        }


Then in my Page_Load method I called:

Code: C#
SetDefaultButton(this.Page, PDFUrl, PDFUploadButton);


When the user types return in the text box, however, an Exception is thrown by function _eofi_a().
The message is "b has no properties".

Is there a way you would recommend to direct the return key to call click()?

- Paul

eo_support
Posted: Friday, August 22, 2008 12:17:59 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,098
Hi,

We can't spot anything abnormal from the above code. We tried it on both IE and FireFox and it works fine as well. Can you post a test page that demonstrates the problem?

Thanks!
P. Chernoch
Posted: Friday, August 22, 2008 2:56:15 PM
Rank: Newbie
Groups: Member

Joined: 8/18/2008
Posts: 9
I found a resolution. Instead of using the code I showed you, I added a defaultbutton attribute to the form, and everything works fine.

I know there was a bad interaction with google analytics. I think I broke the event handling mechanism by directly setting the handler/

- Paul
eo_support
Posted: Friday, August 22, 2008 3:19:44 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,098
Glad to hear you worked it out. Thanks for the update!



You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.