Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 18th, 2004, 06:09 PM
Authorized User
 
Join Date: Sep 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Decide what buttons to control which textboxes?

On a page I have:
<asp:textbox id="textbox1" runat="server/>
<asp:button id="button1" runat="server" text="1" onclick="Sub1"/>

<asp:textbox id="textbox2" runat="server/>
<asp:button id="button2" runat="server" text="2" onclick="Sub2"/>

<asp:textbox id="textbox3" runat="server/>
<asp:button id="button3" runat="server" text="3" onclick="Sub3"/>

When I put the marker in textbox2 or 3 and hit Enter the page assumes that I did hit button1, so it runs Sub1...!
Therefor my question is:
How can I take control of this? There must be a way!

Realising that ASP.NET only handles one server-side form-tag really irritates me...Do I have to stay that way?

 
Old December 19th, 2004, 11:35 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

In your code-behind, you can use the button's keypress attribute to trap the textbox keypress. Then for a given condition (keypress is the enter key), you can call the appropriate button's click event:

First we'll construct the javascript with a placeholder for the button postback call. Then well add in the button postback call. Then we'll apply the javascript call to the textbox's onKeyPress client side event handler (using the attributes collection).

sKeyPress = "if(event.keyCode==13) {0}; return false;"
sKeyPress = String.Format(sKeyPress, GetPostBackEventReference(button1))
textbox1.Attributes.Item("onKeyPress") = sKeyPress

Do this for each textbox.
 
Old December 21st, 2004, 09:26 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I would think that you could associate the button with a sub in the codebehind using the Handles attribute.

For example,
Code:
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
   some code
End Sub
You could do this for each button.

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old December 21st, 2004, 12:49 PM
Authorized User
 
Join Date: Sep 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by planoie
 In your code-behind, you can use the button's keypress attribute to trap the textbox keypress. Then for a given condition (keypress is the enter key), you can call the appropriate button's click event:

First we'll construct the javascript with a placeholder for the button postback call. Then well add in the button postback call. Then we'll apply the javascript call to the textbox's onKeyPress client side event handler (using the attributes collection).

sKeyPress = "if(event.keyCode==13) {0}; return false;"
sKeyPress = String.Format(sKeyPress, GetPostBackEventReference(button1))
textbox1.Attributes.Item("onKeyPress") = sKeyPress

Do this for each textbox.
Ok, thanks, I'll try these examples. /Moss






Similar Threads
Thread Thread Starter Forum Replies Last Post
Check the referring page and decide on opening a n pkballa Javascript 1 March 29th, 2006 02:02 AM
Parameters that decide which graph? inge_03 Crystal Reports 0 March 27th, 2006 04:59 AM
Using Visual Basic behind Excel Control Buttons Danielle Beginning VB 6 0 January 10th, 2006 06:32 AM
control groupings (radio buttons and check boxes) John K. King Javascript 5 April 5th, 2004 11:43 PM
Monthview control and textboxes eresina Pro VB 6 2 October 2nd, 2003 04:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.