Sender as objetc, E as EventArgs

gracemule

New Member
Hi,<BR>I've seen something that I can't quite understand about ASP.NET:<BR>Sub Page_Load(Sender as Object, E as EventArgs)<BR>Is there any article or kind enough person out there that explains why Sub Page_Load is declaring these two parameters?<BR><BR>Thanks,<BR><BR>Edwin<BR>This is the standard argument list for an event in asp.net. Page_load is the event that happens when your page loads... In this case the arguments are pretty much useless... However if you have say an asp.net button control..<BR><BR><asp:button id="btSomeButton" onClick="btSomeButton_click" runat="server" /><BR><BR>The btSomeButton_click procedure that you would write would need the same parameter list as the page_load event. Sender contains the object.. In this case btSomeButton. So you can access it through Sender. This is useful when you have more then one control sharing the same event handler or maybe you want to reuse the event somewhere else without rewriting it I guess. <BR><BR>Get a book man. A pretty good one is sams teach yourself asp.net in 21 days. It covers alot of ground and it answered alot of questions for me.If you take the line Sub Button_Click( s As Object, e As EventArgs ):<BR><BR>The first parameter, or "s" in this case, represents the Object that raised the event. In this instance, this would most likely represent a button. As the gentleman who responded before me stated, this would be handy if you're trying to determine which button was clicked, etc.<BR><BR>The second parameter, or "e" in this case, represents information specific to the event that was raised. In the instance of Button controls, this parameter contains no properties. Other controls such as the ImageButton DO contain information. In that case, the EventArgs parameter would include information about the pixel coordinates on the control clicked.
 
Back
Top