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

Posted on 2004-11-08
Last Modified: 2008-03-06
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:
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!!!!!

Question by:heyday2004
    LVL 9

    Assisted Solution


    Hi Scott, "creates" the html-page for your client depending on your aspx and the code-behind every roundtrip again.
    so if you set a server side control to invisible thinks this control isn't needed on the client and so it isn't part of the page send to the client.

    What do you intent to do? Submitting a form, when the user hits the ENTER key?
    then you should catch the this event with javascript and submit the form in this event

    function keypress() {

      if (window.event.keyCode == 13) {
          return false;

    Hope this helps,

    LVL 9

    Expert Comment


    ... and in your html-control add

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

    (or whatever control you use...)
    LVL 7

    Accepted Solution

    instead of making btnEnter.visible = false;
    try this


    This will make the control invisible in the browser and the error will not shown.

    LVL 20

    Expert Comment


    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.cancel = true;;



     else if (document.getElementById){

      if (event.which == 13){


       event.cancel = true;;



     else if(document.layers){

      if(event.which == 13){


       event.cancel = true;;




    // -->


    Author Comment

    Brilliant! Thanks a lot for all the answers!


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now