I have 13 years of programming experience in DESKTOP applications like Oracle, VB and Delphi....But I am new to ASP.NET 2.0 so just cant get my mind off from desktop programming...my question is that when we develop a web based application how can I trap
TEXTBOX control events like 'On Enter Key', LostFocus, GotFocus and other important events...as I am in a middle of developing a Accounting System so suppose If I want user to take input in all CAPS and If the focus go on next TextBox Control i want to do
something or when I leave the TextBox control I want to do some actions...how to do all these in ASP.NEt.....plz clear my concept as I havent see any LIVE .NET web application...
Hi the intellisense of visual studio already suggests some events that belong to a textbox control (notified with a small lightning icon).
However, I think that your question is more how you can attach client side events to a textbox.
E.g. when a user presses a character you want to convert it to uppercase.
This will attach the javascript function 'ConvertToUpper' to your textbox. It will be fired "onkeyup".
Ofcourse you do still need to write this function :)
When you have coded the above make sure you view the source of the page on which your textbox is to really see what is going on...
HTH
please mark answers as 'Answered' and post back solutions when you figure stuff out that isnt in the post already.
This will convert all entry in a TextBox to upper case:
TextBox1.Attributes.Add("onblur", "JavaScript:this.value = this.value.toUpperCase();")
or to lower case:
TextBox1.Attributes.Add("onblur", "JavaScript:this.value = this.value.toLowerCase();")
Thank you guys for the reply...I was out of the town so cudnt reply back quickly...I appreciate your answers...NC your reply was in detail and I understood correctly...before accepting your answer just a quicky...can you give me the url where I can find
the EVENT LIST ..
TextBox1.Attributes.Add("onkeypress", (THIS "onkeypress" PART) ...cause I dont know what onblurs does..so I would like to know the detail list of events I can trap...
joshtheflame
Member
1 Points
4 Posts
TextBox Control Events
Feb 11, 2008 09:24 AM|LINK
Hi There,
I have 13 years of programming experience in DESKTOP applications like Oracle, VB and Delphi....But I am new to ASP.NET 2.0 so just cant get my mind off from desktop programming...my question is that when we develop a web based application how can I trap TEXTBOX control events like 'On Enter Key', LostFocus, GotFocus and other important events...as I am in a middle of developing a Accounting System so suppose If I want user to take input in all CAPS and If the focus go on next TextBox Control i want to do something or when I leave the TextBox control I want to do some actions...how to do all these in ASP.NEt.....plz clear my concept as I havent see any LIVE .NET web application...
Regards
Josh
Peter Smith
Contributor
4604 Points
2092 Posts
Re: TextBox Control Events
Feb 11, 2008 10:50 AM|LINK
Hi the intellisense of visual studio already suggests some events that belong to a textbox control (notified with a small lightning icon).
However, I think that your question is more how you can attach client side events to a textbox.
E.g. when a user presses a character you want to convert it to uppercase.
You can do so from code-behind as follows:
textbox1.attributes.add("onkeyup","javascript:ConvertToUpper(this);")
This will attach the javascript function 'ConvertToUpper' to your textbox. It will be fired "onkeyup".
Ofcourse you do still need to write this function :)
When you have coded the above make sure you view the source of the page on which your textbox is to really see what is going on...
HTH
NC01
All-Star
82559 Points
15430 Posts
MVP
Re: TextBox Control Events
Feb 11, 2008 01:01 PM|LINK
This will convert all entry in a TextBox to upper case:
TextBox1.Attributes.Add("onblur", "JavaScript:this.value = this.value.toUpperCase();")
or to lower case:
TextBox1.Attributes.Add("onblur", "JavaScript:this.value = this.value.toLowerCase();")
LostFocus:
TextBox1.Attributes.Add("onblur", "JavaScript:alert('onblur fired');")
GotFocus:
TextBox1.Attributes.Add("onfocus", "JavaScript:alert('onfocus fired');")
On Enter Key:
TextBox1.Attributes.Add("onkeypress", "JavaScript: textBoxOnKeyPress(this);")
And add this JavaScript to the HTML of the page.
<script type="text/JavaScript">
<!--
function textBoxOnKeyPress(elementRef)
{
var keyCode = (event.which) ? event.which : window.event.keyCode;
if ( keyCode == 13 )
{
alert('Enter key pressed');
}
}
// -->
</script>
Good luck, there is a lot to learn in comparison to windows desktop apps!
NC...
joshtheflame
Member
1 Points
4 Posts
Re: TextBox Control Events
Feb 13, 2008 05:49 AM|LINK
Thank you guys for the reply...I was out of the town so cudnt reply back quickly...I appreciate your answers...NC your reply was in detail and I understood correctly...before accepting your answer just a quicky...can you give me the url where I can find the EVENT LIST ..
TextBox1.Attributes.Add("onkeypress", (THIS "onkeypress" PART) ...cause I dont know what onblurs does..so I would like to know the detail list of events I can trap...
THANKS again.
NC01
All-Star
82559 Points
15430 Posts
MVP
Re: TextBox Control Events
Feb 13, 2008 04:26 PM|LINK
The onblur event is fired when an element loses the focus.
As for a list of events, a search on Google found this: http://www.spacecenter.dk/~gvilla/jsref/evnt.htm#1011686
Google is your best friend on things such as this.
NC...
joshtheflame
Member
1 Points
4 Posts
Re: TextBox Control Events
Feb 14, 2008 04:31 AM|LINK
NC you rock man...thanks alot for this help...worth learning from this forum....
Regards.