By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,426 Members | 3,407 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,426 IT Pros & Developers. It's quick & easy.

TextChanged vs. [Button] Click Event

P: n/a
I'm new to ASP.net programming so excuse my ignorance if the following
question seems overly simplistic.

I've created a simple Login form with 3 primary WebControls:
- A TextBox for the Username
- A TextBox for the Password
- A Button labelled "Submit"

If the user enters a correct username/password combination then he's taken
to another page. But if either or both are incorrect then a simple message
is displayed. Everything works perfectly fine if he clicks the Submit
button. But I activated the same code for the TextChanged event of the
Password TextBox so that the user could just press 'Enter' after entering the
password.

For reasons I can't explain, though I think it has something to do with
PostBack, the message is not displayed when TextChanged event is fired. Yet
it does work correctly when the button's Click event is fired. Why is this?

--
Robert W.
Vancouver, BC
www.mwtech.com

May 2 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
It should work in either case. Double check the control flow of your code to
ensure the event with your logic is called.

The text change event probably is not the most efficient however, since you
would have to test both in the username and password text changed events -
either one might have changed on the post back.

The button click might work better and it can receive and event when the
enter key is pressed.

- Steve

"Robert W." wrote:
I'm new to ASP.net programming so excuse my ignorance if the following
question seems overly simplistic.

I've created a simple Login form with 3 primary WebControls:
- A TextBox for the Username
- A TextBox for the Password
- A Button labelled "Submit"

If the user enters a correct username/password combination then he's taken
to another page. But if either or both are incorrect then a simple message
is displayed. Everything works perfectly fine if he clicks the Submit
button. But I activated the same code for the TextChanged event of the
Password TextBox so that the user could just press 'Enter' after entering the
password.

For reasons I can't explain, though I think it has something to do with
PostBack, the message is not displayed when TextChanged event is fired. Yet
it does work correctly when the button's Click event is fired. Why is this?

--
Robert W.
Vancouver, BC
www.mwtech.com

May 2 '06 #2

P: n/a
Steve,

Thanks for responding. Can I ask you to elaborate on the last thing you
said: "The button click might work better and it can receive an event when the
enter key is pressed."

How do I get the Button Click event to "receive" the event of teh Enter key
being pressed? If I could do that, I think it would simplify things greatly!

--
Robert W.
Vancouver, BC
www.mwtech.com

"Steve Goodyear" wrote:
It should work in either case. Double check the control flow of your code to
ensure the event with your logic is called.

The text change event probably is not the most efficient however, since you
would have to test both in the username and password text changed events -
either one might have changed on the post back.

The button click might work better and it can receive and event when the
enter key is pressed.

- Steve

"Robert W." wrote:
I'm new to ASP.net programming so excuse my ignorance if the following
question seems overly simplistic.

I've created a simple Login form with 3 primary WebControls:
- A TextBox for the Username
- A TextBox for the Password
- A Button labelled "Submit"

If the user enters a correct username/password combination then he's taken
to another page. But if either or both are incorrect then a simple message
is displayed. Everything works perfectly fine if he clicks the Submit
button. But I activated the same code for the TextChanged event of the
Password TextBox so that the user could just press 'Enter' after entering the
password.

For reasons I can't explain, though I think it has something to do with
PostBack, the message is not displayed when TextChanged event is fired. Yet
it does work correctly when the button's Click event is fired. Why is this?

--
Robert W.
Vancouver, BC
www.mwtech.com

May 2 '06 #3

P: n/a
Hi Steve,

After I read your response, I did some more research on my own. I
discovered these two articles:

http://aspnet.4guysfromrolla.com/articles/060805-1.aspx
http://www.beansoftware.com/ASP.NET-...Enter-Key.aspx

Both seemed to be describing my problem exactly, though I was puzzled
because I already did have 2 textboxes. Regardless, in the 2nd one I saw
this code:

TextBox1.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if
((event.which == 13) || (event.keyCode == 13))
{document.getElementById('"+Button1.UniqueID+"').c lick();return false;}} else
{return true}; ");
So I added it and voila, all works great now!
--
Robert W.
Vancouver, BC
www.mwtech.com

"Robert W." wrote:
Steve,

Thanks for responding. Can I ask you to elaborate on the last thing you
said: "The button click might work better and it can receive an event when the
enter key is pressed."

How do I get the Button Click event to "receive" the event of teh Enter key
being pressed? If I could do that, I think it would simplify things greatly!

--
Robert W.
Vancouver, BC
www.mwtech.com

"Steve Goodyear" wrote:
It should work in either case. Double check the control flow of your code to
ensure the event with your logic is called.

The text change event probably is not the most efficient however, since you
would have to test both in the username and password text changed events -
either one might have changed on the post back.

The button click might work better and it can receive and event when the
enter key is pressed.

- Steve

"Robert W." wrote:
I'm new to ASP.net programming so excuse my ignorance if the following
question seems overly simplistic.

I've created a simple Login form with 3 primary WebControls:
- A TextBox for the Username
- A TextBox for the Password
- A Button labelled "Submit"

If the user enters a correct username/password combination then he's taken
to another page. But if either or both are incorrect then a simple message
is displayed. Everything works perfectly fine if he clicks the Submit
button. But I activated the same code for the TextChanged event of the
Password TextBox so that the user could just press 'Enter' after entering the
password.

For reasons I can't explain, though I think it has something to do with
PostBack, the message is not displayed when TextChanged event is fired. Yet
it does work correctly when the button's Click event is fired. Why is this?

--
Robert W.
Vancouver, BC
www.mwtech.com

May 2 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.