Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 21st, 2004, 02:12 PM
Authorized User
 
Join Date: Jun 2003
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default sender as object...

hi there everybody
I am a beginner .aspx developer. I keep seeing
Code:
Sub whatever(sender As Object, E As Eventargs)
around but i am unsure of what it is doing.
could somebody please explain? I can never see any use of either Sender or E within the code.

Cheers
Andy
 
Old August 22nd, 2004, 12:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

What you are seeing are two arguments that an event handler accepts. The first (sender as Object) is the object on which the event has occurred (a button in a button click event).

The second is of type EventArgs or a derived type. This argument depends on the event and contains event related data. For example, a button click event accepts the System.EventArgs type. A paint event accepts the System.Windows.Forms.PaintEventArgs type.

J
 
Old August 22nd, 2004, 04:07 AM
Authorized User
 
Join Date: Jun 2003
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

and now it all becomes clear.

so if i under stand you correctly, sender takes the ID of the object (eg button1) and E As eventargs takes "doThis" if the asp button looked like

<asp:button id="button1" OnClick="doThis" runat="server" />

Am i correct?
Andy
 
Old August 22nd, 2004, 11:50 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Sender is an object that contains a reference to the object that raised the event. So you could write:

CType(sender, Button).Text = "Text Changed"

and change the text of your "button1".

EventArgs represents any other arguments that need to be passed from the sending object to the event handler. An example of this is the Form.Closing event. It passes an instance of CancelEventArgs to the event handler which can be used to cancel the form's closing. So if you had:

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        e.Cancel() = True
End Sub

the form would not close.

HTH

J





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to solve the binding for sender? alexcym Visual Basic 2005 Basics 2 April 7th, 2008 03:27 PM
Ch 17 - Sender Object not working? deanC4 BOOK: Beginning ASP.NET 2.0 and Databases 1 April 18th, 2007 01:25 PM
How to set X-Sender in ASP.Net ramuis78 ASP.NET 2.0 Basics 5 September 22nd, 2006 03:49 PM
How to capture sender email address (from) Axxess Access VBA 0 July 26th, 2005 04:52 AM
"Sender As Object, E As EventArgs) anpham ASP.NET 1.0 and 1.1 Basics 3 July 7th, 2005 08:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.