Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2004-11-08
5
Medium Priority
?
258 Views
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: 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
0
Comment
Question by:heyday2004
5 Comments
 
LVL 9

Assisted Solution

by:Thalox
Thalox earned 400 total points
ID: 12530731

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
 
LVL 9

Expert Comment

by:Thalox
ID: 12530741

... and in your html-control add

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

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

Accepted Solution

by:
sukumar_diya earned 1600 total points
ID: 12531305
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
 
LVL 20

Expert Comment

by:ihenry
ID: 12531428

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
 

Author Comment

by:heyday2004
ID: 12547254
Brilliant! Thanks a lot for all the answers!

-Scott
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

810 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