Advertisement

04.06.2004 at 03:21AM PDT, ID: 20944907
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

ASP.NET - Default button when user hits [Return]

Zone: .NET
Tags: button, default
I need a simple way to make a particular (image)button on a web form fire when the user presses the return key, please.
 
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: sumo_the_cat
Solution Provided By: dfiala13
Participating Experts: 6
Solution Grade: A
Views: 308
Translate:
Loading Advertisement...
04.06.2004 at 03:44AM PDT, ID: 10764502

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.06.2004 at 04:26AM PDT, ID: 10764715

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.06.2004 at 06:31AM PDT, ID: 10765687

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.06.2004 at 07:47AM PDT, ID: 10766460

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.06.2004 at 07:50AM PDT, ID: 10766479

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.06.2004 at 08:32AM PDT, ID: 10766862

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.06.2004 at 09:32AM PDT, ID: 10767432

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.06.2004 at 09:33AM PDT, ID: 10767440

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.06.2004 at 09:36AM PDT, ID: 10767479

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.06.2004 at 12:03PM PDT, ID: 10768806

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.06.2004 at 01:00PM PDT, ID: 10769226

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.06.2004 at 03:19PM PDT, ID: 10770285

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.06.2004 at 08:24PM PDT, ID: 10771623

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.07.2004 at 03:57AM PDT, ID: 10773462

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.07.2004 at 06:34AM PDT, ID: 10774608

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.07.2004 at 07:56AM PDT, ID: 10775383

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.08.2004 at 04:16PM PDT, ID: 10788041

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.08.2004 at 04:19PM PDT, ID: 10788066

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.28.2004 at 02:46PM PDT, ID: 10943906

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.10.2004 at 01:34PM PDT, ID: 11283503

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.10.2004 at 01:35PM PDT, ID: 11283507

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.15.2005 at 08:31AM PST, ID: 13315365

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
04.06.2004 at 03:44AM PDT, ID: 10764502

Rank: Guru

Source :
http://www.utmag.com/September2003/Page3.asp



private void Page_Load(object sender,
    System.EventArgs e)
{
   // This causes the page to associate Enter
   // key with btnSearch click.
   Page.RegisterHiddenField( "__EVENTTARGET",
       "btnSearch" );
}

Note
 
04.06.2004 at 04:26AM PDT, ID: 10764715
In VB.NET, this should work, right?

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Set default button to btnSearch.
        Page.RegisterHiddenField("__EVENTTARGET", "btnSearch")

    End Sub

I doesn't, though. Any ideas why? (there is certainly more than one textbox on the form, although one of them is yellow for no reason whatsoever.)
Thanks,
Pete.
 
04.06.2004 at 06:31AM PDT, ID: 10765687

Rank: Master

>> although one of them is yellow for no reason whatsoever
Do you have a Google toolbar?  if so Check the Google Toolbar Options and turn off AutoFill. The toolbar checks for fields that look like likely candidates for autofill and highlights them.  
 
04.06.2004 at 07:47AM PDT, ID: 10766460
Clever! Nice one dfiala13. You can have some extra points! I would have wasted days on that, in all likelihood. But do you know why the reason why the above isn't working?
 
04.06.2004 at 07:50AM PDT, ID: 10766479
On a similar (completely unrelated!) note, do you how to get rid of all the double spacing on my web forms? It's really annoying, but I want to use flow layout. I'll post extra points outside this q.
 
04.06.2004 at 08:32AM PDT, ID: 10766862

Rank: Master

>> But do you know why the reason why the above isn't working?
Good question.  I'll see if I can see what's what.

>>double spacing on my web forms
What do you mean?  I use flowlayout all the time.
 
04.06.2004 at 09:32AM PDT, ID: 10767432
Well, when I press enter to start a new line, I get large gaps in between each line.
 
04.06.2004 at 09:33AM PDT, ID: 10767440

Rank: Master

OK, Though it would be nice if were that easy
Reason  Page.RegisterHiddenField( "__EVENTTARGET",
       "btnSearch" );
 won't work because

the script has no idea what to do with it.  If you look at your html source after the page renders you won't see anything referencing it (unless perhaps you have some validators turned on -- but even then it won't work because it will get overwritten in the validation script).

No, you need to do some keycapture in javascript and have it set the event target and tnen call the submit when the enter key is pressed.
 
04.06.2004 at 09:36AM PDT, ID: 10767479

Rank: Master

The VS designer is throwing <p> tags around each line.  You can either change the default style of the <p> or simply remove them or don't use the designer for entering long text blocks.
 
04.06.2004 at 12:03PM PDT, ID: 10768806
Don't know Jscript... This must be a common requirement - surely there's a way to do it?

This should be a different thread, but i guess it's "line-height" that i need to change. But to what value? visual studio is only suggesting 'Normal'.
 
04.06.2004 at 01:00PM PDT, ID: 10769226

Rank: Master

>>This must be a common requirement - surely there's a way to do it?
There is -- Javascript.  This is all client-side behavior.

You capture the enter key down event and call the form submit. Here's an example...

http://dotnetjunkies.com/WebLog/darrell.norton/archive/2004/03/03/8374.aspx

You can also attempt to set the tab order.  First button in the tab order "usually" gets the default submit

you can change the line height to a value in pixels line-height: 15px.  
 
04.06.2004 at 03:19PM PDT, ID: 10770285
I've had a look at that URL before, but left feeling confused. Will it work with imagebuttons? Can you tell me exactly what to do to get it to work in VS.NET with VB.NET? Java confuses the heck out of me, being an MS Access programmer by heart.
 
04.06.2004 at 08:24PM PDT, ID: 10771623

Rank: Master

Sure it will work with imagebuttons.

And remember its not Java, its Javascript, which is just a handy way to deal with client-side events on an HTML page.  ASP.NET makes extensive use of it for the validation controls and most third party custom controls are loaded with it.  So time to get unscared, because if you want to get the most out of ASP.NET (or any web development tool) you are going to have to at least get comfortable with Javascript.  Otherwise your developing will be severely handicapped.

We'll skip the script regsitering for now and do it the brute force way...

Put this in the HTML of your page, somewhere between the header tags...

<SCRIPT language=""javascript"">

<!--

function fnTrapKD(btn, event){

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

  }

 }

}

// -->

</SCRIPT>

All this does is capture the enter key.  All the if-else stuff is because not all browsers are created equal they all have different ways of identifying elements (which is a royal pain).

Now, add this method to your code-behind or your VB script.  This will add an onkeydown trap to every text control you send to it...

Private Sub SetDefaultButton( txt as TextBox, defaultButton as ImageButton )
 txt.Attributes.Add("onkeydown", "fnTrapKD(" + defaultButton.ClientID + ",event)");


End sub

Finally, in your Page_load event handler, add a call to the method for each text box you have. It will set the default button to use for every textbox.  You can use the same button for each textbox or different ones.

SetDefaultButton(TextBox2, Button2)

That's all there is to it. Hit the enterkey and submit.

Accepted Solution
 
04.07.2004 at 03:57AM PDT, ID: 10773462
That works perfectly. Some points for you my friend:
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20946265.html

Is there a way to capture "form"-wide events? I'd like to have an application-wide toolbar which uses the function keys as shortcuts. Is this possible, and could it be incorporated with this solution?

I've ballsed up my <P> tags though! I'll have to start again.
 
04.07.2004 at 06:34AM PDT, ID: 10774608
I might be wrong here but I think you can press ctrl-M or shift-M instead of the return key in Flow layout which inserts <br> instead of <p>, Give it a try I'm sure that worked for me.
Assisted Solution
 
04.07.2004 at 07:56AM PDT, ID: 10775383

Rank: Master

>>Is there a way to capture "form"-wide events?
You can try to add a onkeydown trap to the body element...

<body onkeydown="return MyTrap(event);">

and add a script similar to the one above to deal with it.  Of course to really make it useful, you'd want to put it in a user control and have it alter the body element on whatever page it was put on.
Assisted Solution
 
04.08.2004 at 04:16PM PDT, ID: 10788041
davisg090767: that just inserts <P>s, but thanks for telling me about the <br> tag - that gives me a new line with no space.

I'm going to need some help with all this formatting business, especially tags. VB.NET is fine, but I'm finding this web stuff much more fiddly than I'd expected..!

I can't work out how to change the double line-spacing in between the <P></P> tags. I don't want double, but single isn't much use either when a small gap is needed.

I will post another question though.

Thanks for all the help. dfiala13, you know your stuff.
 
04.28.2004 at 02:46PM PDT, ID: 10943906
Thanks for the solution!  It was really helpful.

If you know you want the same default button behavior for all TextBox controls in your page, you can iterate over the Controls.  This takes less typing than adding it manually for all text boxes.  (C#)

            public void SetDefaultButtons( Button button )
            {
                  foreach ( Control control in this.Controls )
                  {
                        if ( control is TextBox )
                        {
                              SetDefaultButton((TextBox)control, button);
                        }
                  }
            }

 
06.10.2004 at 01:34PM PDT, ID: 11283503
holding down the shift key in design mode inserts a line-break and not a new paragraph
it works almost all microsoft products, macromedia and a bunch of others, too.
 
06.10.2004 at 01:35PM PDT, ID: 11283507
correction: holding down the shift key WHILE YOU HIT ENTER inserts ...
 
02.15.2005 at 08:31AM PST, ID: 13315365
Hi, in relation to the posting by "dfiala13" for this solution mine doesnt work, when im in my textbox i still get a  server roundtrip rather than the javascript function been invoked ?.  i have looked at the source after the page as rendered and the onkeydown attribute has been added suceesfully from C# - onkeydown="fnTrapKD(Datechange)" - so this is ok, but in this function all i have now is an alert statement and even that doesnt get triggered, its like the page/browser is overriding the added attribute. any ideas
steve
 
 
20080236-EE-VQP-29