Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Saturday, September 20, 2003 7:43 PM
Hi My Friends The following code in VB.NET return value of “Text” property in the “sender” opject Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click -> Me.TextBox1.Text = sender.Text End Sub But In C# I Get Compiler Error for The Following Code private void button1_Click(object sender, System.EventArgs e) { -> this.textBox1.Text = sender.Text; } I Get This Error Message 'object' does not contain a definition for 'Text' This Mean “sender” dose not content definition for 'Text' How can I get values of (sender) object in C# ?????
All replies (5)
Saturday, March 20, 2010 5:35 PM ✅Answered
Hi,
try this:
private void button1_Click(object sender, System.EventArgs e)
{
Button btn=(Button)sender;
this.textBox1.Text = btn.Text;
}
Monday, March 22, 2010 4:19 AM ✅Answered
Sender object is type of object any time if you want to use any property/attribute of sender object first you need to type cast it with your desire object.
for this problem first you need to change the sender object ot button then you can use the Text property of button.
Monday, April 12, 2010 1:58 AM ✅Answered
You can try some code like this. There are as follows
Me.TextBox1.Text= ((XX DataType)sender).Text .
or Me.TextBox1.Text= (sender as XX DataType).Text
pay attention plz, The sender's dataType must be a event source.
Sunday, September 21, 2003 1:33 PM
I get the Answer …. Using The Following piece of cede private void button1_Click(object sender, System.EventArgs e) { -> this.textBox1.Text = ((button1)sender).Text }
Saturday, March 20, 2010 5:00 PM
sorry wrong thread.