protected void page_load(object sender,EventArgs e)
why we use object sender and eventargs e?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
CrishPosted Apr 13, 2011, 8:13 AM
This solve the problem page load
it is a standard in .NET that event handlers have this signature, usually declared by some delegate types for example EventHandler. sender references the object that raised the particular event, for example with Button's Click it would let you reference the Button control via sender argument.
EventArgs represents the data related to that event, and can be used to pass parameters, state information whatsoever to the event handler for the handling code to decide what to do. In this case it is just EventArgs which represents empty event arguments but for example if you have ImageButton's Click handler, you'll note that it's event arguments provide you access to the X and Y coordinates. In other words, Event args can be represented by more specific classes with event related data, depending on the control
Soft CornerPosted Apr 12, 2011, 2:58 AM
When an event is fired it will send a reference of the object that the event is fired from in the sender parameter and any additional information in the e parameter. e is usually of type EventArgs which does not provide usefull information but most classes derive a new class from EventArgs, add additional properties to them and use them as the second parameter of their events. This way the user will be notified of any additional information when handling those events.
Also, If you want to call the page_load function in another function, it depends on whether you are using sender and e in your event handler or not, if you don't you can simply pass nulls as both parameters i.e. Page_Load(null, null)
Ankit NandekarPosted Apr 12, 2011, 2:25 AM
you can use sender like
CheckBox chk=(sender) CheckBox;
The EventArgs parameter contains the additional information about the event.