Determine the Control Events fired in Page Load Event

Suppose If i have a button control on my form and i click on button to post back, in this case Click Event of the button will called after Page Load Event.

I need to know how can i determine which Event of which control is fired in Page Load Event before the itself control's event called.

Do let me know If you don't get my point please.


"Hope its your Solution so Mark it as Answer"

Ahmad Sheikh
Microsoft Valuable Geek
http://sharpcontents.blogspot.com
0
Ahmish
1/15/2009 12:25:57 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

7 Replies
1362 Views

Similar Articles

[PageSpeed] 58
Get it on Google Play
Get it on Apple App Store

If I understand your question, I believe that you are asking for which control events fire during the Page_Load event.  If this is your question, then the answer is Load.

The Page_Load event is called which then the Load event for each control is called.  After this, all of the other control events are called, such as a Button's Click event, etc.

When you finished, then the LoadComplete event is called (available only to versions 2.0 and higher).

Is this what you're looking for?  If not, please clarify.


Christopher Reed
"The oxen are slow, but the earth is patient."
0
Careed
1/15/2009 1:22:36 PM

You can use this to see which control caused the postback:

if ((Request.Params.Get("__EVENTTARGET") == btnMyButton.ClientID.Replace("_", "$")))
{
    //do something
}


Hanan Schwartzberg
--------------------
http://www.lionsden.co.il
0
lionscub
1/15/2009 1:23:11 PM
Hi,
read this
http://geekswithblogs.net/mahesh/archive/2006/06/27/83264.aspx
-------------------------------------------------
Jürgen
0
siedler
1/15/2009 1:24:45 PM

 You can use the hidden variable  __eventtarget to find the control that caused the event

Request.Form("__EVENTTARGET")


Vikram
www.vikramlakhotia.com


Please mark the answer if it helped you
0
vik20000in
1/15/2009 1:25:40 PM

I have a simple page with a Button, when i click on button the page is posted back and the Click Event of Button called but i found null by using Request.Form("__EVENTTARGET") or Request.Params.Get("__EVENTTARGET") in Page Load Event. I am not getting the clicked event of Button.


"Hope its your Solution so Mark it as Answer"

Ahmad Sheikh
Microsoft Valuable Geek
http://sharpcontents.blogspot.com
0
Ahmish
1/20/2009 5:20:52 AM

Ahmish:

I have a simple page with a Button, when i click on button the page is posted back and the Click Event of Button called but i found null by using Request.Form("__EVENTTARGET") or Request.Params.Get("__EVENTTARGET") in Page Load Event. I am not getting the clicked event of Button.

As far as I know, if you add a button control into web page. You can not get the name of control with Request.Form("__EVENTTARGET")  method, because the page will math the name of control in postback data from ViewState. If in this case, the block code of JavaScript will not be generated. You can check it if it is be generated. such as:

function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
But if you add a LinkButton into web page. You can get the name of control with Request.Form("__EVENTTARGET") . Because it is regrister the event by using
 Page.GetPostBackEventReference(this, "") method.
Acually, you can try to pay more attention to this article about IPostBackEventHandler :
1. Ipostbackeventhandler:
http://msdn.microsoft.com/en-us/library/system.web.ui.ipostbackeventhandler.raisepostbackevent.aspx [You can know about the methods and event in IpostBackEventHandler].

Gary yang - MSFT
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Gary
1/20/2009 10:11:24 AM

Gary yang - MSFT:

Ahmish:

I have a simple page with a Button, when i click on button the page is posted back and the Click Event of Button called but i found null by using Request.Form("__EVENTTARGET") or Request.Params.Get("__EVENTTARGET") in Page Load Event. I am not getting the clicked event of Button.

As far as I know, if you add a button control into web page. You can not get the name of control with Request.Form("__EVENTTARGET")  method, because the page will math the name of control in postback data from ViewState. If in this case, the block code of JavaScript will not be generated. You can check it if it is be generated. such as:

function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
But if you add a LinkButton into web page. You can get the name of control with Request.Form("__EVENTTARGET") . Because it is regrister the event by using
 Page.GetPostBackEventReference(this, "") method.
Acually, you can try to pay more attention to this article about IPostBackEventHandler :
1. Ipostbackeventhandler:
http://msdn.microsoft.com/en-us/library/system.web.ui.ipostbackeventhandler.raisepostbackevent.aspx [You can know about the methods and event in IpostBackEventHandler].

 

Thank you 

 You are right we can get the TargetEvent of the LinkButton but Request.Form is a collection not a method in C#.

We can get the value of the targeted event by using the following syntax

Request.Form["__EVENTTARGET"]

Request.Form.Get("__EVENTTARGET")

Request.Params.Get("__EVENTTARGET")
 


"Hope its your Solution so Mark it as Answer"

Ahmad Sheikh
Microsoft Valuable Geek
http://sharpcontents.blogspot.com
0
Ahmish
1/23/2009 6:21:41 AM
Reply:

Similar Artilces:

How to prevent page load event from firing on any other event fired.
Hi to all, I m creating controls dynamically on page load event but now what problem i m facing is that after page load event fired once when i m clicking submit button then page load fires again and it changes the value of  controls. so now can anyone tell me how can I prevent page load event to fire on any other event. Please answer me. Thanx in advance.   To stop a control from doing a postback, you can set it's AutoPostBack property to false. To avoid re-initializing code on postbacks: protected void Page_Load(object sender, EventArgs e) { if (IsPostBack ...

loading controls dynamically in content page and firing the js events and codebehind events
Hi, I have master page and cotent page.Now in the content page I am binding the master page. In the content page I need to load the controls dynamically and fire javascript events for the controls loaded and also codebehnind events. Also how when I try to load the controls dynamically the css settings are changed for the master page.How to prevent from changing the style sheet properties also. How to do this? thanks   thanks   You can add controls dynamically to the content place holder by doing something like this: Label l = new Label(); l.Text = "So...

Master Page's Page Load firing twice on events called from other Page events
I have numerous pages tied to my MasterPage that controls 2 Always visible extenders for User Reminders and a Counter. I would like them to only fire on a Page_Load once, not twice. I have read a million posts about AutoEventWireupset to false, but on all my pages it is set to true and on those pages the events only fire once. The Master page is giving me problems on events firing twice. Any suggestions? here is some code... protected void Page_Load(object sender, EventArgs e) {if (!Page.Master.IsPostBack) {  I call 2 stored procedures here that should only fire once on a Page_Lo...

To access a control placed in a web user control which is loaded during page load in button click event
How can I access a control in a web user control in a button click event , the user control is loaded in page load.Thanks & Regards,Abhiram Reddy Mekha. Try checking this... http://microsoft.apress.com/asptodayarchive/73869/event-handling-between-custom-user-controls-that-are-loaded-at-run-time http://aspalliance.com/565_Dynamic_Loading_of_ASPNET_User_Controls http://www.beansoftware.com/ASP.NET-Tutorials/Controls-Run-Time.aspx http://stackoverflow.com/questions/92792/user-control-created-dynamically-not-able-to-handle-events-on-postback http://www.codersource.net/asp_net_user_c...

How other Events fire before page load events
Hi all,  In my application, I have a gridview in update panel. I have set link buttons for first, previous, next and last. Set page size of gridview as 5. Gridview have Row_Created and Data_Bound event. When I started to debug first time it goes in page load event. But when I clicked on last button of gridview it directly goes to gridview's event and not in page load event. Why this happened? Please tell me solution. niteensapkal:But when I clicked on last button of gridview it directly goes to gridview's event and not in page load event. it should... if last butt...

How to fire events in other web form from other web form ?
Suppose that I have A and B web form. I want to trigger B web form's Page_Load event from A web form. How can I do that ? Thanks in advanced WilbertWilbert Bujn Create a public method in B that call the load method : public void Load(object sender, System.EventArgs e) { Page_Load(sender, e) ; } In the page_load of A, instanciate a B object and then call the function B myB = new B() ; myB.Load() ; Quicky Thank you quicky, it works fine. WilbertWilbert Bujn...

web page opened as dialog does not fire page load event
All,I use the following code to open a web page  as a dialog formMe.btnAddInstruction.Attributes.Add("onclick", "var strReturn; strReturn = window.showModalDialog('AddInstruction.aspx',null,'toolbar:no;menubar:no;status:no;dialogWidth:350px;dialogHeight:350px;dialogHide:true;help:no;scroll:no');")The web page which is being opened has a page load event which populates combo boxes on the web page. However this page load event doesn't fire when the page is opened as a dialog but instead when the page is closed. Now I have a feeling its because the javascript used to open the web pa...

C# .NET need button to fire without fire page load event
I have a asp.net button on my form. I need to fire click event of button without firing page load event of page. Anybody know what the trick is? Thanks in advance. Hi there! Then you shouldn't use the asp.net's WebControls.Button but instead use normal html button because WebControls.Button always fires the post-back. You must use a javascript function to do something when the button is clicked. <input type="button" value="Click me!" onclick="Clicked();"> .... //Then you must have a function "Clicked()": <script lan...

Page with 3 user controls is firing Page.Load event 4 times
No Master page is involved.  AutoEventWireUp=False is set in the user controls as well as the page. I also removed the background image on the body of the page. Does anybody have any suggestions as to what can be the causes  of this behavoir or how to fix it?  Thanks! I did notice if I removed regular img tags two to be exact from the page, the load only fired twice then.   After looking at where the requests are coming in from closer, it looks like the problem revolves around how the authorization is being defined in the web.config and not actually the...

What control fired the page load event?
Hi to all and thanks in advance for helping me with this issue..... I have a form to update some products. The form has a DropDownList that binds to a datareader that includes a list of products to update. I have the dropdownlist setup that everytime the value changes the page reloads and loads the product values into several text and label controls. I also have a button to submit the changes and update the DB. My problem is that when I select and edit a product and then submit the form via the button the page_load event is fired first reloding the original product values and then it r...

Button CLick Event + Page Load Event ( Why does Page load clear all my variables )
super asp noob here ---and i hve to get this done asap --- thxn everyone for reading and responding heres my program in psuedo code page load () { make_table() }   public make_ table () { make a table - read data from a database- set  data -- store lots of data in arrays and variables }   button1_click () { get_data }   public get_data() { get all  the data from the variables-- read from the  table--+ all the variables store the data }  --------------------------------------  basically the user can enter in data&nb...

Using a user control 2 times on a page: first one fires all events, second one fires all events but not 4 buttons
Hello!Edit solved:The problem was that depending on the databind i didn't add the buttons to the control tree instead of simple set visible to false. This worked fine for the first user control cause databinding was triggered on Page_Load but for the secon one the databidning took place later on so the condition not to add the buttons to the control tree set in. The simple solution was to always add the buttons to the control  tree and then check on Pre_render if the visaibility had to be set to false.So always keep in ind:1) Add controls to the control tree for the postback ev...

Can I determine in page load or data load, if a item command was fired. Event expert needed.
My question is how can I determine in page load or data load, if a item command was fired.   These events occur before itemcommand!  Here is the situation.  On a datagrid is a link button that posts back, issues and item command to move to another page.  I want the redirect to occur on the postback  and not on the client side. The problem is that the query to load the datagrid is slow.  The event order is to do a page load, then the data load for the grid, and THEN the item commend.  Since I don't care about showing the grid again when the l...

Web User Control - Button Click
I have a web user control which is has one Button control on it. It has a event for handling the click... if I put this user control ( button ) at the top  of the page, the click event does not get fired just page is refreshed...but where as if I move to the bottom of the page, ButtonClick is fired ???? I am completely clueless why is this change of behavior with respect to the position of the control?? Thanks. could you show us the code that you have problem with ...   Here is the code ( i have taken out the unwanted part of the page ) Please note that the bSave does ...

Web resources about - Determine the Control Events fired in Page Load Event - asp.net.web-forms

Five points determine a conic - Wikipedia, the free encyclopedia
In Euclidean, non-projective geometry , just as two (distinct) points determine a line (a degree-1 plane curve), five points determine a conic ...

How To Determine Whether Your Facebook Customer-Service Efforts Are Effective
Social media analytics provider Crowdbabble added customer support to its mix, launching a new set of social customer service reports that allow ...

How does Facebook determine whether posts from pages are high-quality?
... for Business page on all things News Feed. The newest installment , posted Friday, aims to clarify for page administrators how it determines ...

Twitter Blog: Let your Tweets determine the 2012 Sprite Slam Dunk champi
Twitter Blog Let your Tweets determine the 2012 Sprite Slam Dunk champion 3366100333679041124 Thursday, February 23, 2012 This Saturday, four ...

How does the NYT determine which articles have comments? - Quora
On the The New York Times website, some articles have comment sections, and others don't. It seems like in general higher profile articles have ...

How to determine what Herbs and Spices go best with what dishes - YouTube
Grandma Storn's Herb Wheel is the essential tool for cooking delicious, healthy meals using Herbs and Spices!

Spring, spin and swing: Five factors to determine the 2015 Ashes
Osman Samiuddin cites the state of English pitches and spin effectiveness as among his five factors that will decide the 2015 Ashes series.

Doctors will determine if contract talks are progressing: Davis
Queensland assistant health minister Chris Davis has put his fate in the hands of the state's doctors, saying they are the "ultimate decision ...

App to use 'facial age' to determine health
A new app will use &quot;facial age&quot; images to help doctors identify ageing behaviours in patients.

NFL, San Francisco 49ers, Houston Texans: Jarryd Hayne’s key dates to determine NFL future, starting ...
JARRYD Hayne will take his first competitive snap against NFL opposition this Sunday at 10am (AEST) when the San Francisco 49ers take on the ...

Resources last updated: 12/19/2015 11:46:01 PM