Click here to Skip to main content
15,891,703 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI All,,

I am using a label to display some message on the basis of textboxes,,, Problem is that I want that label to be emptied again when I start to write in the textbox again....

Can anybody give me the hint to do that.. coz i m unable to find any useful event to do that.


:-(
Posted
Updated 19-Jun-13 21:27pm
v3

1. Add onFocus event to TextBox.
XML
<asp:TextBox id="TextBox1" runat="server" onfocus="EmptyLabel()"></asp:TextBox>


2. Write the javaScript function.
JavaScript
<script type="text/javascript">
    function EmptyLabel()
    {
        document.getElementById("lblId").value = "";
    }
</script>
 
Share this answer
 
v2
Comments
VICK 20-Jun-13 7:56am    
Extremely Sorry to bother your dear.. but I have tried your given solution as well as tried the solution by CPallini,, but both are not working.. Actually I am using those controls(textboxes and label) in a table and that table is only populating through a Jquery.. So I am afraid that already working Jquery is stopping all this.. I am novice in this field,, so Kindly guide...
Not working, means, are you facing any problem?

If it is populating through through jQuery, then also dynamically add the events to the controls. Else post the codes here or you can create a fiddle so that I can check.
VICK 20-Jun-13 8:38am    
well.. I DID ALL THE THINGS IN THE WAY YOU TOLD ABOVE LIKE..

i added the script as it is in ht Header Tag of Design Page.
While I added the "onfocus="EmptyLabel()"" in that textbox from whose focus I want the label to be emptied...But stillthe label is showing same even after populating the textbox next time... :(
Ok. Have you changed the id of label according to your label id.

And yes, please see on Console tab of FireBug in FireFox, if there are any issues reported.
VICK 21-Jun-13 0:34am    
Ya I have changed the lblId to lblInfo which is the ID of my label used.. but same.. :( and there is no issue reported in firebug tooo.
Empty the label content in TextBox.GotFocus[^] event handler.
 
Share this answer
 
Comments
VICK 20-Jun-13 7:56am    
Extremely Sorry to bother your dear.. but I have tried your given solution as well as tried the solution by Tadit Dash,, but both are not working.. Actually I am using those controls(textboxes and label) in a table and that table is only populating through a Jquery.. So I am afraid that already working Jquery is stopping all this.. I am novice in this field,, so Kindly guide...

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