What exactly will contain and its use of object sender, EventArgs e as paramenter for Methods or Events

Posted by Girish578 under C# on 3/29/2010 | Views : 1929 | Status : [Member] | Replies : 2
What exactly will contain and its use of object sender, EventArgs e as paramenter for Methods or Events ?

Please help me with an example in detail.




Responses

Posted by: Raja on: 3/29/2010 [Member] Starter

Up
0
Down
To explain the answer of your question, take this example.

Button
<asp:Button id="btn" runat="Server" onclick="LoadData" />


Onclick Event
protected void LoadData(object sender, EventArgs e)

{
// object - will be the button that fires this event
// EventArgs - any arguments value can be accessed in to this method via CommandArguments property of the button
}


Hope this will help.




Regards,
Raja, USA

Girish578, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sagarp on: 3/30/2010 [Member] Bronze

Up
0
Down
The EventArgs are arguments that the implementor of this event may find useful. With OnClick it contains nothing good, but in some events, like say in a GridView 'SelectedIndexChanged', it will contain the new index, or some other useful data.


protected void btSomeButton_Click (object sender, EventArgs ea){

Button btnSomeButton = sender as Button;
btnSomeButton.Text = "I was clicked!";
}


Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/

Girish578, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response