DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Wed, 25 Jul 2007 17:38:18 -0000,    posted on: microsoft.public.dotnet.framework.aspnet.webcontrols        back       

Thread Index
  1    unknown


Image Button onkeypress   
I know this has been beaten a hundred different ways, but I've tried
them all and I'm stuck.  I have a web control on a web form.  The web
control is for logging in and all it has are two textboxes (username
and password) and an imagebutton Submit button.  The main form also
has a handful of image buttons.  I need the Submit imagebutton to fire
when the user hits the Enter key.  Right now when Enter is pressed,
the first button on the page fires instead, which happens to be the
Home button, and the user is taken from the Login page to the Home
page.

I know this behavior is simply another "feature" of ASP.NET in that
all asp buttons are rendered as html submit buttons, so the first one
on the page is fired on Enter.  But, I also know that hundreds of
programmers have worked around this through a few lines of
javascript.  Every method I've tried just results in java syntax
errors, odd behavior such as "object expected" java errors, no
behavior at all.  Here are the scripts I've tried so far to no
avail....

======================
Method 1:
<script language="javascript">
function SubmitForm(btnName) {
 if ( event.keyCode == 13 ) {
 event.returnValue=false;
 var btn = document.forms[0][btnName];
 btn.click();
 }
}
</script>

then add an onkeypress call to SubmitForm passing the webcontrol's
ibSubmit button clientID name.

======================
Method2:
function document.onkeydown() {
    if ( event.keyCode ==  13 ) {
        Form1.WebControlForm1_ibSubmit.click();
       event.returnValue=false;
   }
}

======================
Method3:
<script>
       function submitForm()
       {
               if (event.keyCode == 13)
               {
                       Form1.submit();
               }
       }
</script>

then add an onkeydown call in the main page's Body tag or in the
password textbox's attributes

======================
Method4:
<script>
       function clickButton() {
           if (event.keyCode == 13) {
               document.form.button1.click();
              return false;
           }
       }
</script>

then add an onkeydown call in the main page's Body tag or in the
password textbox's attributes

======================
Method5:
<script>
   function catchEnter(){
       if(event.keyCode == 13)
           __doPostBack('<%=ibSubmit.ClientID%>','');
           return false;
       else
           return true;
   }
</script>

then add an onkeypress call in the main page's Body tag or in the
password textbox's attributes.  Here I've tried dynamically
determining the imagebutton's client id as above, and I've hardcoded
the resulting client ID directly into that function.

======================

Any help would be greatly appreciated.  I've been looknig at this too
long and can't figure out why nothing is working.  I know I can use
different types of buttons, but this spec is company determined and
needs to be an imagebutton control due to reasons unrelated to this
post.

Thank all!!

Cory
Date:Wed, 25 Jul 2007 17:38:18 -0000   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us