Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to implement method on the event of label text is changed. how to implement it?
Posted
Updated 27-Oct-15 1:55am
v2
Comments
Ralf Meier 27-Oct-15 7:44am    
I'm not sure what you try to achieve.
A Label raises an Event "TextChanged".
What is your Problem ?
Member 11922776 27-Oct-15 7:47am    
label arise label_Click event when double click on label. I want label textchange event instead.
Ralf Meier 27-Oct-15 7:56am    
This happens by working with the Visual Studio Editor.
The Click-Event is automaticly selected. But you could also change this to the TextChanged-Event. Take a look to my Solution ...
Krunal Rohit 27-Oct-15 8:01am    
I'd rather use the readonly textbox that look like a label.

-KR
BillWoodruff 27-Oct-15 11:39am    
Why ?

There is no such event is asp.net but you can achieve similar functionality using JQuery.
Check these links for further information-
asp label text changed event in Jquery[^]
how to fire event on label text change[^]

Hope, it helps :)
 
Share this answer
 
Comments
Member 11922776 27-Oct-15 7:49am    
Yes Sir Looking for same but in Windows From application.Is JQuery applicable for winforms?
Suvendu Shekhar Giri 27-Oct-15 7:53am    
OK.Then please remove the tag ASP.Net from the question.
Suvendu Shekhar Giri 27-Oct-15 7:54am    
removed the ASP.Net tag from the question
Member 11922776 27-Oct-15 7:57am    
Ok,Sorry for that. Is there any solution for this?
Labels don't have text changed events, because they can't receive the keyboard focus, so all changes must be down to your own code rather than user actions.

If you need a change event as a result of your code actions, then consider using a read-only TextBox instead.
 
Share this answer
 
Comments
Member 11922776 27-Oct-15 7:53am    
Is not possible with label?
Ralf Meier 27-Oct-15 7:53am    
@OG:
Sorry but I must correct you :
Label derives from Control and it has a TextChanged-Event - why not ...?
OriginalGriff 27-Oct-15 8:35am    
Brain death on my part: increase caffeine intake...
Ralf Meier 27-Oct-15 9:01am    
OK ... I think like you.
That helps EVERYtime.
BillWoodruff 27-Oct-15 11:42am    
Knowing you are fallible, once in a blood-moon Sunday, gives me the courage to go on :)
Try it like this :

C#
private void Label3_TextChanged(System.Object sender, System.EventArgs e)
{
    Button3.Text += "-";
}

private void Button3_Click(System.Object sender, System.EventArgs e)
{
    Label3.Text += "x";
}
 
Share this answer
 
Comments
Member 11922776 27-Oct-15 8:05am    
Its not working
Ralf Meier 27-Oct-15 8:09am    
Have you connected the right eventhandlers to the both methods ? Perhaps you do it in the Designer on the Propertygrid of both Controls.
Ralf Meier 27-Oct-15 9:03am    
What about your Problem now ?
Is it working like you want ?
If Yes : please accept my answer formally ...
If No : give more Information ...
BillWoodruff 27-Oct-15 11:40am    
imho, asking the OP to accept your answer is not a good idea.
Ralf Meier 28-Oct-15 5:40am    
Perhaps you are right ...
But to get a Feedback from the Inquirer when he has written, that the Suggestion is not working, would be nice ...
Considering the only way to change the test of a Label is through your code, why are you even trying to use the TextChanged event? If your code is changing the text, just call the frickin' method that you want to put in the TextChanged event handler after changing the text of the Label!
 
Share this answer
 
Comments
BillWoodruff 27-Oct-15 11:41am    
Dave, I think it's possible (though, perhaps unlikely) that some other code object could have a reference to the Label, and change its text.
Dave Kreskowiak 27-Oct-15 14:19pm    
Possible, but not exactly a good method of communication between two pieces of code that handle data. Events on UI controls are meant to be used to control the UI, nothing more.

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