locked
Determine the Control Events fired in Page Load Event RRS feed

  • Question

  • User-134772610 posted

    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.

    Thursday, January 15, 2009 7:25 AM

Answers

  • User1616291716 posted

    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].
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 20, 2009 5:11 AM

All replies

  • User1759999623 posted

    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.

    Thursday, January 15, 2009 8:22 AM
  • User1059346350 posted

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

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

    Thursday, January 15, 2009 8:23 AM
  • User-1486182340 posted
    Hi, read this http://geekswithblogs.net/mahesh/archive/2006/06/27/83264.aspx
    Thursday, January 15, 2009 8:24 AM
  • User312496708 posted

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

    Request.Form("__EVENTTARGET")

    Thursday, January 15, 2009 8:25 AM
  • User-134772610 posted

    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.

    Tuesday, January 20, 2009 12:20 AM
  • User1616291716 posted

    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].
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 20, 2009 5:11 AM
  • User-134772610 posted

    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")
     

    Friday, January 23, 2009 1:21 AM