Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 21st, 2004, 02:12 PM
Authorized User
 
Join Date: Jun 2003
Location: , , United Kingdom.
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
  #2 (permalink)  
Old August 22nd, 2004, 12:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
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
  #3 (permalink)  
Old August 22nd, 2004, 04:07 AM
Authorized User
 
Join Date: Jun 2003
Location: , , United Kingdom.
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
  #4 (permalink)  
Old August 22nd, 2004, 11:50 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
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
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:23 AM.


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