Ads

Captured Technology - Blog

Clearing a text box in ASP.Net using Javascript

Clearing a text box in ASP.Net using Javascript

I was looking for a way to clear a textbox on focus in an ASP.Net application today and found some Microsoft examples using scripts in the Markup language and then referencing the script using the old onfocus="SomeFunction();". But then I found the best way that works easily and keeps the code in the code behind.

In the Page Load event of you page or of your Masterpage, place one line of code which adds an attribute to the textbox and you are finished:

Me.txtSomeBox.Attributes.Add("onFocus", "this.value=''")

As you can see, you can modify the attribute to contain an object event and then place any code within the value property to be executed. You can have as many attributes for as many objects as you like.

Blog Directory

Latest technology news.
 Patrick Stevens
 536  246405  4/17/2024

Translate

Categories

Blog Calendar