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
heyday2004Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ThaloxCommented:

Hi Scott,

asp.net "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 asp.net 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) {
      __doPostBack('btnEnter','');
      return false;
  }
}

Hope this helps,


Thalox
0
ThaloxCommented:

... and in your html-control add

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

(or whatever control you use...)
0
sukumar_diyaCommented:
instead of making btnEnter.visible = false;
try this

btnEnter.Style.Add("display","none");

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

Suku
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ihenryCommented:

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

  }

 }

}

// -->

0
heyday2004Author Commented:
Brilliant! Thanks a lot for all the answers!

-Scott
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.