imagine kitty magazine

Skip over navigation
  • Categories

    • ASP.NET
    • Bible tags
    • Christianity
    • Classic ASP
    • Firearms
    • Humor
    • Random
    • Trackbacks
    • Web design
    • Web standards
    • Why I am the way I am
    • Wordpress
  • Pages

    • Bible verse tags 2.0
    • Portfolio
    • Steps to building a proper web page
  • Blogroll

    • benthack
    • ASP.NET Resources
    • Bible Dude
    • Cake Wrecks
    • Church Communications Pro
    • Creating Passionate Users
    • Dossy’s Blog
    • Gary Turner’s html & css workshop
    • I Will Teach You To Be Rich
    • Pescatarian Cooking
    • SystemDotWeb
    • The Nice Jewish Website
    • The Sneeze
    • Tyssen Design
  • Info

    • home
    • Log in
    • contact mark
    • blogs that link here*
    • valid xhtml
    • valid css
    • valid rss2
    • rss feed
Sigarms P229

spam this

« FPDF.asp carriage return / line feed in MultiCell
Getting Business Contact Manager for Outlook 2007 installed »

Firing a click event using the enter key

This one had me stumped for a few minutes. I had a text box that would post to a google search. Entering text in and hitting the enter key would just post back to the page and have no effect.

Hmm. Frustrating. I don’t expect everyone to type in their search criteria and grab the mouse to click the tiny little button so here’s what you have to do.
<asp:Panel ID="searchPanel" DefaultButton="topSearchButton" runat="server">
<asp:TextBox ID="topSearch" columns="21" CssClass ="formbox" runat="server" EnableViewState="False" />
<asp:ImageButton ID="topSearchButton" ImageURL="images/bg/buttonGoHome.gif" OnClick="topSearchButton_Click" CSSClass="buttonGoHome" AlternateText="Submit" runat="server" />
</asp:Panel>

OnClick event:
protected void topSearchButton_Click(object sender, ImageClickEventArgs e)
{ Response.Redirect("http://www.google.com/u/xxx?domains=www.xxx.edu&sitesearch=www.xxx.edu&q=" + topSearch.Text);
}

The DefaultButton attribute names the ID of the button you want to fire. The only issue is it doesn’t work on a text box (or any other form item) it only works on a Panel. I suppose it makes sense because you usually don’t just have one form field and a button, it’s usually many text boxes, any of which can fire the click event using the enter key.

I figured there was no point in having ViewState on a text box that posts to another site so EnableViewState should be set to False in this case.

This entry was posted on 15Jan08 @ 2311 and is filed under ASP.NET. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Sponsored links

Site5 $5 Hosting Dealemail address

Amazon Wishlist

Hello, friends! I've decided to put my Amazon wishlist online. If you feel nice today you can purchase one of the items listed and it will be shipped to my door. My birthday is May 13th and I will gladly accept gifts for any Christian or Jewish holiday. Thank you for your support.

  • RESTful .NET - $26.39
  • jQuery in Action - $21.29
  • People Are Idiots and I Can Prove It!: The 10 Ways You Are Sabotaging Yourself and How You Can Overcome Them - $16.50
  • Programming ASP.NET MVC - $29.69
  • Digital TENS Unit - Powerful Multi-mode TENS - One Week Sale! - n/a
  • Learning WCF: A Hands-on Guide - $25.18
  • Top Secret! - $4.09
  • Kentucky Fried Movie - $4.35
  • The Normal Christian Life - $2.51
  • The Holy Spirit and Reality - $2.51
  • The Richest Man in Babylon - $2.29
  • Tough Guys Don't Dance - $3.54
  • Get Crazy - n/a
  • Don't Let The Irs Destroy Your Small Business: Seventy-six Mistakes To Avoid - $6.88
  • Don't Make Me Think: A Common Sense Approach to Web Usability, 2nd Edition - $19.00
  • Dress Your Best: The Complete Guide to Finding the Style That's Right for Your Body - $11.23
  • Perfect Pushup - Original - $31.96
  • Pro ASP.NET MVC Framework (Pro) - $34.64
  • Benny Hill - Complete & Unadulterated Megaset (1969-1989) - $54.97
  • Young Doctors In Love - $2.78
  • Great White North - $6.37
  • Transylvania 6-5000 - $4.08
  • The Party - $6.14
  • Circuit-Bending: Build Your Own Alien Instruments (ExtremeTech) - $6.00

Disclaimer: All product data in this section belongs to Amazon.com or respective site(s). No guarantees are made as to accuracy of prices or product information. Prices listed are accurate as of the date/time indicated or otherwise within the last 24 hours. Prices and product availability are subject to change. Any price displayed on the Amazon website at the time of purchase will govern the sale of this product.

Site search and links

I'm a friend of Israel

Open Trackback Alliance Logo


Widgetize!
WWW is deprecated
no-WWW class B
*blogs that link here powered by Technorati

©2008 imaginekittymagazine