Thursday, March 22, 2012

simple default button focus

I'm going crazy people, I've got 3 asp buttons and 3 textboxes. Like this:

TEXTBOX1 <BUTTON1>
TEXTBOX2 <BUTTON2>
TEXTBOX3 <BUTTON3>

I know about the server side method, but when the textbox2 is focus and I hit enter then the button2 must go off. When I focus textbox3 then button3 must go off. It must be done with Java, Anyone?i dont think javascript is your answer, it sounds like you should be using multiple forms.

or else use textchanged event to work out which one changed (wont work if they type in mutliple and hit enter on 1 though) but that minor problem could be fixed with ajavscript by erasing the text on the other textboxes when they change focus
Do you have any example for me in ASP.Net -> VB code?
i meant to just use the textchanged events on the textboxes...

as for the multiple form way, this isnt very nice to deal with in asp.net, more a classic asp thing, so i don't actually recommend that.
Can you fix this in VB.Net code then?
In the textbox's tag,

onkeydown="CheckKey(event);"

Then write your function

function CheckKey() {
if (event.keyCode == 13) {
document.getElementById("btn1").click();
}
}

Note, that you will have to modify this for all three of your buttons, and in addition, you'll have to generate this code using Page.RegisterClientScriptBlock so that you can replace btn1 with the actual ClientID of your buttons.

0 comments:

Post a Comment