By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,731 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,731 IT Pros & Developers. It's quick & easy.

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

P: 16
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
Share this Question
Share on Google+
4 Replies


P: 16
hmm, no ideas?
Apr 19 '07 #2

Frinavale
Expert Mod 5K+
P: 9,731
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

P: 16
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

P: 16
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.