473,509 Members | 3,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TextChanged vs. [Button] Click Event

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
3 4253
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2171
by: jorge | last post by:
Hello I have the following situation: (everything is dynamic (controls.add)) 1. Button.Init { WasButtonClickFired = true } 2. TextBox.TextChanged { WasButtonClickFired?
2
3965
by: Owin | last post by:
Hi all, I've created an User control. It's an extension of a textbox wich has some extra properties so that validation becomes a lot faster. The control wordks great if autopostback is on. When...
1
4485
by: Samuel Chan | last post by:
I used the textchanged event of textbox and set the autopostback property to true. The textchanged event should fire when the content of the textbox is changed and user tab out of the textbox...
0
1350
by: gaurav | last post by:
hi, I have a problem, How do i use TextChanged Event by clicking on Button. When i changed the text in text box and moving the focus from there then it is working but i have one calender popup...
2
3002
by: gaurav | last post by:
hi, I have a problem, How do i use TextChanged Event by clicking on Button. When i changed the text in text box and moving the focus from there then it is working but i have one calender popup...
1
2004
by: Spencer H. Prue | last post by:
I have a textbox and a button on my asp.net form. I have some Smtp code in my button click procedure. When the user hits the return for the textbox the button procedure runs. When the button is...
2
1517
by: moi | last post by:
Hello, I have a formview with a dropdownlist,a textbox and a button to add a new row with this fields. Everything works good (i have my new record) when i click on the button but how to be faster...
0
1299
by: moi | last post by:
Hello, I have a formview with a textbox and a button with an Insert commandname. I have put a textchanged event without a autopostback and i see that when i click the button, the textchanged's...
5
5235
by: S_K | last post by:
This is a weird problem.. I have a page with a textbox and a button (along with a bunch of other stuff). Both the textbox and the button have their SEPERATE events defined for the textchanged...
0
7234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7412
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5652
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4730
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.