Exploring the depths and potentials of ASP.NET RSS 2.0 or Subscribe to .BenRush by Email
 Thursday, April 05, 2007

ASP.Net doesn't like multiple forms on a webform; indeed, it is the paradigm now that one webform has one "form" on it (hence the name - webform). However, as people begin buliding tricky input forms on their pages it becomes necessary to specify "default" buttons throughout the page. As an example, say you're filling out one of two forms on a page and you want to hit the Enter key to submit your form data. If there are multiple forms on the page, then you will run into a problem as the browser attempts (and possibly fails) to ascertain which button should recieve the keydown event.

In ASP.Net the Panel control supports a default button so that you can "subsection" out your form with various different buttons being the default. If focus happens to be on a control within a panel that has one of these secondary submit buttons specified, then THAT button will get respond to your Enter keystroke.

Here's an example:

First, create a webform with two panels on it like this:



When you run the above form, regardless of whether your cursor is in the textbox of the first form or the second form, hitting ENTER will always act as if you clicked the button in the first.

To submit the button in the second via the ENTER key if your cursor is active in that textbox (or any control in that panel), do the following to the panels:

            First form:
            <asp:Panel ID="Panel1" DefaultButton="Button1" runat="server" Height="127px" Width="151px">
                &nbsp;
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Button" /></asp:Panel>
            <br />
            Second form<br />
            <asp:Panel ID="Panel2" DefaultButton="Button2" runat="server" Height="127px" Width="151px">
                &nbsp;
                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" /></asp:Panel>
            </div>

Notice how I specify the "DefaultButton" property in the panel. Now if your cursor is active in any control within Panel2, Button2 will be the default submit button for your ENTER keystroke.

Addendum:

Please see here for the documentation to this attribute. It is available in the .Net frameworks 2.0 and 3.0 only.

Recommended reading:


kick it on DotNetKicks.com
Thursday, April 05, 2007 9:04:17 PM (Central Standard Time, UTC-06:00)  #    Comments [3] - Trackback
ASP.Net | Programming
Tracked by:
http://freewebs.com/aspxfaq/04/sitemap15.html [Pingback]
http://freewebs.com/toltom/08/sitemap4.html [Pingback]
http://freewebs.com/toltom/04/texas-unclaimed-money.html [Pingback]
http://freewebs.com/toltom/01/sitemap11.html [Pingback]
http://freewebs.com/toltom/01/atlantic-city.html [Pingback]
"http://fartooblog.tripod.com/2.html" (http://fartooblog.tripod.com/2.html) [Pingback]
"http://fartooblog.tripod.com/196.html" (http://fartooblog.tripod.com/196.html) [Pingback]
"http://rma7dj.org/sitemap16.html" (http://rma7dj.org/sitemap16.html) [Pingback]
"http://awlelm.org/sandra-nude.html" (http://awlelm.org/sandra-nude.html) [Pingback]
"http://topslots.nl.eu.org/13/sitemap12.html" (http://topslots.nl.eu.org/13/site... [Pingback]
"http://freewebs.com/amexa/33/www-directtv-com.html" (http://freewebs.com/amexa/... [Pingback]
"http://freewebs.com/amexa/19/vernal-equinox.html" (http://freewebs.com/amexa/19... [Pingback]
"http://freewebs.com/amexa/36/blind-copy.html" (http://freewebs.com/amexa/36/bli... [Pingback]
"http://pinofranc.homestead.com/01/red-wings.html" (http://pinofranc.homestead.c... [Pingback]
"http://pinofranc.homestead.com/04/bush-gardens-williamsburg-virginia.html" (htt... [Pingback]
"http://pinofranc.homestead.com/01/marie-osmond.html" (http://pinofranc.homestea... [Pingback]
"http://r0o5g-xxx.com/jessica-simpson-pussy.html" (http://r0o5g-xxx.com/jessica-... [Pingback]
"http://o4bwn-www.com/brazilian-shemale.html" (http://o4bwn-www.com/brazilian-sh... [Pingback]
"http://javboonews.netfirms.com/155.html" (http://javboonews.netfirms.com/155.ht... [Pingback]
"http://maoguunews.netfirms.com/63.html" (http://maoguunews.netfirms.com/63.html... [Pingback]
"http://pasbeenews.tripod.com/176.html" (http://pasbeenews.tripod.com/176.html) [Pingback]
"http://ywwhr-ooo.com/gay-asian-man.html" (http://ywwhr-ooo.com/gay-asian-man.ht... [Pingback]
"http://javboonews.netfirms.com/179.html" (http://javboonews.netfirms.com/179.ht... [Pingback]
"http://wepyv-hhh.com/young-lesbos.html" (http://wepyv-hhh.com/young-lesbos.html... [Pingback]
"http://xxx3t-xxx.biz/survivor-cbs.html" (http://xxx3t-xxx.biz/survivor-cbs.html... [Pingback]
"http://naidu-www.biz/hot-mom-next-door.html" (http://naidu-www.biz/hot-mom-next... [Pingback]
"http://c5cza-eee.com/sexy-massage.html" (http://c5cza-eee.com/sexy-massage.html... [Pingback]
"http://freewebs.com/tferma/04/hgh-spray.html" (http://freewebs.com/tferma/04/hg... [Pingback]
"http://freewebs.com/niret/00/screen-names.html" (http://freewebs.com/niret/00/s... [Pingback]
"http://freewebs.com/amexa/46/las-vegas-attractions.html" (http://freewebs.com/a... [Pingback]
"http://freewebs.com/tiltak/14/www-staples-com.html" (http://freewebs.com/tiltak... [Pingback]
"http://freewebs.com/niret/07/virus.html" (http://freewebs.com/niret/07/virus.ht... [Pingback]
"http://p5roc-rrr.com/fuck-my-ass.html" (http://p5roc-rrr.com/fuck-my-ass.html) [Pingback]
"http://unibetkom.5gbfree.com/00227-blog.html" (http://unibetkom.5gbfree.com/002... [Pingback]
"http://ramambo.nl.eu.org/17/trinity.html" (http://ramambo.nl.eu.org/17/trinity.... [Pingback]
"http://harum.nl.eu.org/google-dom.html" (http://harum.nl.eu.org/google-dom.html... [Pingback]
"http://ramambo.nl.eu.org/windows-me.html" (http://ramambo.nl.eu.org/windows-me.... [Pingback]
"http://fernokom.nl.eu.org/big-ass-black-galleries.html" (http://fernokom.nl.eu.... [Pingback]
"http://monokom.nl.eu.org/free-federal-grants.html" (http://monokom.nl.eu.org/fr... [Pingback]
"http://krpefgb.com/thechildrensplace-com.html" (http://krpefgb.com/thechildrens... [Pingback]
"http://mnbjoxr.com/naked-misty.html" (http://mnbjoxr.com/naked-misty.html) [Pingback]
"http://dero--kom.nl.eu.org/craigslist-portland-or.html" (http://dero--kom.nl.eu... [Pingback]
"http://nasferablog.netfirms.com/128.html" (http://nasferablog.netfirms.com/128.... [Pingback]
"http://hclu7dx.com/avril-lavine-naked.html" (http://hclu7dx.com/avril-lavine-na... [Pingback]
"http://polablog.nl.eu.org/anal-sex-for-woman.html" (http://polablog.nl.eu.org/a... [Pingback]
"http://jyakos9.biz/sex-confessions.html" (http://jyakos9.biz/sex-confessions.ht... [Pingback]
"http://teno--blog.nl.eu.org/lots-of-pussy.html" (http://teno--blog.nl.eu.org/lo... [Pingback]
"http://nasferablog.netfirms.com/8.html" (http://nasferablog.netfirms.com/8.html... [Pingback]
"http://lk2iuen.biz/sex-bed.html" (http://lk2iuen.biz/sex-bed.html) [Pingback]
"http://nasferablog.netfirms.com/565.html" (http://nasferablog.netfirms.com/565.... [Pingback]
"http://moko--kom.nl.eu.org/cute-graphics.html" (http://moko--kom.nl.eu.org/cute... [Pingback]
"http://zxe--blog.nl.eu.org/relapse-records.html" (http://zxe--blog.nl.eu.org/re... [Pingback]
"http://zgzqetw.biz/familysearch.html" (http://zgzqetw.biz/familysearch.html) [Pingback]
"http://natevf--niko.nl.eu.org/teen-boxers.html" (http://natevf--niko.nl.eu.org/... [Pingback]
"http://nasferablog.netfirms.com/251.html" (http://nasferablog.netfirms.com/251.... [Pingback]
"http://zf1y1fs.biz/ebbay.com.html" (http://zf1y1fs.biz/ebbay.com.html) [Pingback]
"http://wwad6lf.biz/peopelmagazine.html" (http://wwad6lf.biz/peopelmagazine.html... [Pingback]
"http://freewebs.com/fremapblog/sitemap5.html" (http://freewebs.com/fremapblog/s... [Pingback]
"http://freewebs.com/sruone/phone-companys.html" (http://freewebs.com/sruone/pho... [Pingback]
"http://freewebs.com/sruone/sitemap374.html" (http://freewebs.com/sruone/sitemap... [Pingback]
"http://lopbafrea.homestead.com/44.html" (http://lopbafrea.homestead.com/44.html... [Pingback]
"http://mernokob.nl.eu.org/girls-age-16-to-17.html" (http://mernokob.nl.eu.org/g... [Pingback]
"http://freewebs.com/vuter/10/worcester-telegram--gazette.html" (http://freewebs... [Pingback]
"http://duter.homestead.com/01/poker-net.html" (http://duter.homestead.com/01/po... [Pingback]
"http://freewebs.com/vuter/05/sitemap6.html" (http://freewebs.com/vuter/05/sitem... [Pingback]
"http://buter.homestead.com/00/kingwood-basketball-league.html" (http://buter.ho... [Pingback]
"http://freewebs.com/datingblogger/1421.html" (http://freewebs.com/datingblogger... [Pingback]
"http://freewebs.com/datingblogger/58.html" (http://freewebs.com/datingblogger/5... [Pingback]
"http://fasxen.netfirms.com/1.html" (http://fasxen.netfirms.com/1.html) [Pingback]

Computers Blogs - Blog Top Sites

Archive
<January 2009>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009
Benjamin Rush
Sign In
Statistics
Total Posts: 444
This Year: 0
This Month: 0
This Week: 0
Comments: 128
Themes
Pick a theme:
All Content © 2009, Benjamin Rush
DasBlog theme 'Business' created by Christoph De Baene (delarou)