Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Enter Key Press imagebutton click event

Posted on 2006-05-26
5
Medium Priority
?
594 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:Gezna
  • 3
5 Comments
 
LVL 5

Expert Comment

by:vinodhsomasekharan
ID: 16774117

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

Accepted Solution

by:
vinodhsomasekharan earned 2000 total points
ID: 16774259
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
 
LVL 27

Expert Comment

by:Sammy Ageil
ID: 16774714
GetPostBackEventReference is available in asp.net 2.0 not asp.net 1.1

http://msdn2.microsoft.com/en-US/library/ms153110.aspx
0
 

Author Comment

by:Gezna
ID: 16783652
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
 
LVL 5

Expert Comment

by:vinodhsomasekharan
ID: 16797869
Hai,

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

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

thanks for the tips yaar...

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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 …
Integration Management Part 2
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
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