473,729 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

16 New Member
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 14193
Spectre1337
16 New Member
hmm, no ideas?
Apr 19 '07 #2
Frinavale
9,735 Recognized Expert Moderator Expert
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.EventArg s) 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
Spectre1337
16 New Member
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.EventArg s) 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
Spectre1337
16 New Member
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
8927
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 code... I never see that explicitly called. Is it supposed to be called from the Global.asa file (still not sure what that is...) Is "session_start" a server-side scripting thing? Or a client-side scripting thing? I'd really appreciate a nice...
3
15242
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 really simple. Just double-click on the event and the definition for that event (along with the method) gets written. I see that the first argument that is set up is "object sender" while the second argument varies with the particular event. ...
0
1059
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 feels weird. I have two projects. One is a simple VC console program. The other is a VB Class Library project (DLL) in which there is a form (Form1) on which there is a button (Button1) and a textbox (TextBox1). Both these controls are public.
2
1133
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 event. Thanks for any help provied.
3
4560
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 Session_Start() { Session.Timeout = 3000; } in global.asax
9
4921
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 fine from a link. The button does bring up the popup window, but when I press the links on the page, it doesn't return or close the window. ****************************************************************************
2
1459
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
1926
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 system.object" other than get its type. Could someone tell me how to extract this info? I don't like the untidy, inefficient and anti-OO coding of using a seperate context menu for each textbox.
4
15688
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
8921
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9427
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9284
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9202
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9148
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4528
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2683
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.