Click here to Skip to main content
15,888,251 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi everybody here,

I have a textbox in my web page and through codebehind i added onchange event for the textbox but it is not working while onblur event working.... i changed the event onchange to onkeypress and ontextchanged but none is working the code below is the one i am using.. what is wrong in my code , if somebody knows pls help me..


SQL
Dim ctrlSelect As TextBox = CType(l.FindControl("txtSelect"), TextBox)
        If Not ctrlSelect Is Nothing Then
            ctrlSelect.AutoPostBack = True
            ctrlSelect.Attributes("onblur") &= "Updatedata('" & drItem("PATIENT_NOTE_CONTROL_ID") & "', '1');"
            ctrlSelect.Attributes("ontextchanged") &= "Updatedata('" & drItem("PATIENT_NOTE_CONTROL_ID") & "', '1');"
        End If

<
Posted
Updated 4-Jan-15 21:04pm
v2
Comments
Sergey Alexandrovich Kryukov 5-Jan-15 2:45am    
Does the code under "if" statement execute? Did you use the debugger?
—SA
pitchaiyan 5-Jan-15 2:47am    
Yes!.. the onblur event is working well. but onchange doesn't..
Praveen Kumar Upadhyay 5-Jan-15 2:47am    
AutoPostBack property is true or not?
pitchaiyan 5-Jan-15 2:50am    
AutoPostBack property is being false.. Mr.Pravee Kumar Upadhyay should i change that to true..? if yes but onblur working well..
Praveen Kumar Upadhyay 5-Jan-15 3:02am    
I am a little confused with the VB code. I am a C# developer, but try using AutoPostBack to true.

You are assigning even handlers to client-side events...onblur works for you because this is a real event, however no such client side event as ontextchanged...
There are two options:
1. You want client side event for change - it called onchange...
2. You want to use the server side OnTextChanged event, in which case you have a long way to learn about ASP.NET web technology and how events are working within it...
 
Share this answer
 
Comments
pitchaiyan 5-Jan-15 4:35am    
No..! I used and tried with onchange and onkeypress events also but no luck that is why i used the event name like ontextchanged....
Kornfeld Eliyahu Peter 5-Jan-15 4:40am    
Let me be blunt - go and learn ASP.NET before trying to write a web site using the technology (and after that read my answer again)...
When dealing with web development you need to remember that there are two computers involved. The server that is hosting the web site and the user's computer. If you are wanting to execute code when a textbox's value changes, it just doesn't work the same as it would on a windows form. If it did, then every time a user presses a key in the textbox everything would stop while the data was sent to the server, the textchanged event code would run and then data would be sent back to the user and reload the entire page, etc. Not cool.

This is why you would likely want to do in javascript which runs on the user's computer and doesn't have to send data to/from the server. Basically, there is no textchanged event in javascript. You get OnBlur[^] which is basically a lose focus event.

Technically there is a TextChanged event for a web's textbox, but I the code only gets hit if a textbox value has changed between postbacks...and again, you don't want to do a postback every time a user presses a key in a textbox.

Hope this helps explain.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900