469,964 Members | 1,676 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,964 developers. It's quick & easy.

ASP.NET: Determining the "sender" Object in Page_Load()

Hello,

to my understanding the ASP.NET process works as follows:

1) Page_Init(): At this moment the user should allocate his controls, set their IDs and connect them to the page (Controls.Add()).
2) ASP.NET is parsing the ViewState and the rest of the HTTP Request. It now synchronizes the controls that the user has allocated in Page_Init() according to their ID.
3) Page_Load(): At this point the user controls should be initialized according to the ViewState. Further loading may occur.
4) Event Handlers are called.
5) etc.

Now, if we consider that the event handlers are called at step 4) and that ASP.NET had already found the sender object (the first parameter of "void something_Click( object sender, EventArgs e )") by comparing the user control IDs with the IDs inside ViewState, then the sender object should already be known at "Page_Load()".

How can I retrieve the sender object in Page_Load()? If that's not directly possible, how can I retrieve its control ID?
Apr 18 '07 #1
4 13432
hmm, no ideas?
Apr 19 '07 #2
Frinavale
9,735 Expert Mod 8TB
hmm, no ideas?
Using ASP.NET with VB.NET server side code for my projects, my page load method is declared as such:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load


The sender object is passed into this method as a parameter.
Does this help?
What are you trying to do?

-Frinny
Apr 19 '07 #3
Using ASP.NET with VB.NET server side code for my projects, my page load method is declared as such:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load


The sender object is passed into this method as a parameter.
Does this help?
What are you trying to do?

-Frinny
The sender object that is passed as a parameter to Page_Load() is always the control itself (this). I'm trying to get the sender object of the event (say, if a button was clicked on my table, and if the table defines Page_Load(), i want sender to be the button, not the table).
Apr 19 '07 #4
I've managed to find a way to get to the ID of the sender control:

Expand|Select|Wrap|Line Numbers
  1. protected string EventSenderId
  2.     {
  3.         get
  4.         {
  5.             foreach( string s in Request.Form )
  6.                 if( s.StartsWith( ID ) && s.EndsWith( ".x" ) )
  7.                     return s.Substring( ID.Length + 1, s.Length - ID.Length - 3 );
  8.  
  9.             return null;
  10.         }
  11.     }
This is a very, very ugly way that I would like to avoid ...
Apr 19 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Mercy | last post: by
3 posts views Thread by Christoph Boget | last post: by
2 posts views Thread by Erick | last post: by
2 posts views Thread by romy | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.