Enter Key Press imagebutton click event

Hi,

This should be really simple, but in vb.net asp1.1, I need code that will click an image button when the enter key is hit at any time on the page.

I have tried almost every example I can find, but none of them work. I keep getting object expected javascript error.

Can someone please provide some code and help me troubleshoot?

Thanks
GeznaAsked:
Who is Participating?
 
vinodhsomasekharanConnect With a Mentor Commented:
Hai


if u get any error like __doPostBack() Method Not Found.. or any thing related to this function..

just add the following line to u r page load function on server side

Page.GetPostBackEventReference(ImageButton1)


Regards
Vinu
0
 
vinodhsomasekharanCommented:

Hai,

just try this,

Let the imagebutton name be "ImageButton1"

                  function callPostBack()
              {
                  if(window.event.keyCode==13)
                  {
                           
                     __doPostBack('ImageButton1','OnClick');
                  }
              }

call the above function "callPostBack" in the keypress event of the body tag..

 eg:-  <body onkeypress="callPostBack();"  MS_POSITIONING="GridLayout">

The java script will trigger a postback as if it was initiated by the Imagebutton.. u can handle it on u r server side


hope this helps u

Regards
Vinu
0
 
SammyCommented:
GetPostBackEventReference is available in asp.net 2.0 not asp.net 1.1

http://msdn2.microsoft.com/en-US/library/ms153110.aspx
0
 
GeznaAuthor Commented:
Vinu, basically I used your code except the below worked for me, your line returned something like "object expected" but it got me on the right track.

I swear I tried this before, but things seem to work better on Monday morning than on Friday afternoon ;)

<script language="javascript">
                  //If the enter key is pressed perform the search
                  function callPostBack()
            {
           if(window.event.keyCode==13)
               {
           event.returnValue=false;
           event.cancel = true;
           document.getElementById("imgbtnSearch").click();
               }
            }

</script>
0
 
vinodhsomasekharanCommented:
Hai,

Sorry i just read u r comments today....

"  document.getElementById("imgbtnSearch").click();  "

thanks for the tips yaar...

0
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.

All Courses

From novice to tech pro — start learning today.