473,320 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 14141
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

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

Similar topics

1
by: Mercy | last post by:
Hi, I'm a newbie. I was trying to figure out how to use the Session_start method? The reference books I'm reading say that a session STARTS when "session_start" is called. But ... in their sample...
3
by: Christoph Boget | last post by:
Please forgive my ignorance as I'm still new to developing w/C# (and in windows in general). So if I use the wrong terms, please bear with me. I'm using VS.NET and defining the events have been...
0
by: Sin | last post by:
Hello, I'm currently toying around with using a VB.NET interface in a VC.NET program and I've come across somewhat of a problem. I found a workaround but I figure I must be a bit off cause it...
2
by: Erick | last post by:
Hi, Is there any way that I can know the object that does fires or does postback to the page on the Page_Load event. I tried to use the sender object that is defined as parameter into this...
3
by: Carpe Diem | last post by:
Hello I have an aspx page that loses Session("user") value after a few minutes even after I set <sessionState mode="InProc" cookieless="false" timeout="300"> in web.config and wrote function...
9
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work...
2
by: romy | last post by:
Hello dot.net winforms How Do I make casting from the sender object to controls in the form that called the sub ?
3
by: Alan LeHun | last post by:
I want to attach a context menu to multiple textboxes but I don't know how the extract the name of the textbox that is the subject of the event. I can't seem to do anything with "sender as...
4
by: Rob | last post by:
I see that MsgBox(sender.ToString()) will return a string that includes the Text value of a button... Is there a way to return only the Text value (i.e., some additional property designate) ?
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.