Link to home
Start Free TrialLog in
Avatar of heyday2004
heyday2004

asked on

Why after I set "Enter" button to Invisible, the program doesn't recognize the hidden button anymore?

I have a program and I have an "enter" button (btnEnter) on the page to submit the text field data. I linked the user's press-Enter-key action to this button so that when user press enter, this button will also be submitted. (I followed the article: Submitting default buttons when the user presses the Enter key - finally! link: http://dotnetjunkies.com/WebLog/darrell.norton/archive/2004/03/03/8374.aspx)
It works well although there is still small problem.

Now I don't want the user to see the button anymore so I set its property to invisible. But it doesn't work anymore when user clicks enter key, it says "btnEnter undefined" in the IE page. But when I set btnEnter to Visible, the program works again when the user clicks enter key. Has anyone met this before? How to solve this problem? Any hint is appreciated. Thanks a lot!!!!!

-Scott
SOLUTION
Avatar of Thalox
Thalox

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Thalox
Thalox


... and in your html-control add

<asp:TextBox runat="server" id="tb1" onKeyPress="return keypress();"></asp:TextBox>

(or whatever control you use...)
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Also try

<SCRIPT language=""javascript"">

<!--

function fnTrapKD(btn, event){

  var b = document.getElementByID( btn )   // check if btn exits
  if ( b == null ) return;

 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();

  }

 }

}

// -->

Avatar of heyday2004

ASKER

Brilliant! Thanks a lot for all the answers!

-Scott