Find out the control that initiated the postback event

Discussion in 'ASP .Net' started by Dan, Nov 28, 2003.

  1. Dan

    Dan Guest

    Hi,

    I'd like to find out the control that caused a postback to be raised. Obviously this could simply done in a control event handler. I am not going to do this method and would like no references as to how to do it this way as I already know how.

    I know this may be getting into advanced or unheard of territory.

    I have some custom web user controls that are dynamically created at run time along with other controls. I can still add an event handler to these controls, but unfortunately the event handler wont fire until the controls are re-created on the postback, but I don't want the start-up code running on a post back, I need it to run in the event of the control that cuased the post back. This works fine for my other controls on the form that arn't generated, but will not for this user control, so I need an alternative.

    I need some indication in my page_load (or init) event that tells me that our user control has initiated the postback and to then run start up code.

    Are there any techniques out there that allow me to dig into the postback and discover what control or control type made the postback?

    Another solution I could add a client side handler that could set the value of a checkbox but due to the complexity of the user control I am not going to do that, as a post back could be initiated by a multiple number of events on different controls within the user control.

    Thats my question! Thanks..
    Dan, Nov 28, 2003
    #1
    1. Advertising

  2. Dan

    vMike Guest

    You should be able to add an eventhandler, but if you don't want to you can use Request.Form("__EVENTTARGET"). You must have a control on your form that renders the function __doPostBack(eventTarget, eventArgument) on your page. Many controls will put the function on your page. You could always put a dummy control like a linkbutton or something on your page to force the script to be rendered. Hope this helps.

    "Dan" <> wrote in message news:%...
    Hi,

    I'd like to find out the control that caused a postback to be raised. Obviously this could simply done in a control event handler. I am not going to do this method and would like no references as to how to do it this way as I already know how.

    I know this may be getting into advanced or unheard of territory.

    I have some custom web user controls that are dynamically created at run time along with other controls. I can still add an event handler to these controls, but unfortunately the event handler wont fire until the controls are re-created on the postback, but I don't want the start-up code running on a post back, I need it to run in the event of the control that cuased the post back. This works fine for my other controls on the form that arn't generated, but will not for this user control, so I need an alternative.

    I need some indication in my page_load (or init) event that tells me that our user control has initiated the postback and to then run start up code.

    Are there any techniques out there that allow me to dig into the postback and discover what control or control type made the postback?

    Another solution I could add a client side handler that could set the value of a checkbox but due to the complexity of the user control I am not going to do that, as a post back could be initiated by a multiple number of events on different controls within the user control.

    Thats my question! Thanks..
    vMike, Nov 28, 2003
    #2
    1. Advertising

  3. Dan

    Dan Guest

    Thanks for the reply,

    although sounds nice in theory.

    I tried it and in every instance of a post back

    Diagnostics.Debug.WriteLine(Request.Form("__EVENTTARGET"))

    Diagnostics.Debug.WriteLine(Request.Form("__EVENTARGUMENT"))

    both return a blank string..



    Any ideas ?



    "vMike" <> wrote in message news:bq8kfb$6nl$...
    You should be able to add an eventhandler, but if you don't want to you can use Request.Form("__EVENTTARGET"). You must have a control on your form that renders the function __doPostBack(eventTarget, eventArgument) on your page. Many controls will put the function on your page. You could always put a dummy control like a linkbutton or something on your page to force the script to be rendered. Hope this helps.

    "Dan" <> wrote in message news:%...
    Hi,

    I'd like to find out the control that caused a postback to be raised. Obviously this could simply done in a control event handler. I am not going to do this method and would like no references as to how to do it this way as I already know how.

    I know this may be getting into advanced or unheard of territory.

    I have some custom web user controls that are dynamically created at run time along with other controls. I can still add an event handler to these controls, but unfortunately the event handler wont fire until the controls are re-created on the postback, but I don't want the start-up code running on a post back, I need it to run in the event of the control that cuased the post back. This works fine for my other controls on the form that arn't generated, but will not for this user control, so I need an alternative.

    I need some indication in my page_load (or init) event that tells me that our user control has initiated the postback and to then run start up code.

    Are there any techniques out there that allow me to dig into the postback and discover what control or control type made the postback?

    Another solution I could add a client side handler that could set the value of a checkbox but due to the complexity of the user control I am not going to do that, as a post back could be initiated by a multiple number of events on different controls within the user control.

    Thats my question! Thanks..
    Dan, Dec 1, 2003
    #3
  4. Dan

    Dan Guest

    the items do actually exist in the Request.Form collection...

    but are ""


    "vMike" <> wrote in message news:bq8kfb$6nl$...
    You should be able to add an eventhandler, but if you don't want to you can use Request.Form("__EVENTTARGET"). You must have a control on your form that renders the function __doPostBack(eventTarget, eventArgument) on your page. Many controls will put the function on your page. You could always put a dummy control like a linkbutton or something on your page to force the script to be rendered. Hope this helps.

    "Dan" <> wrote in message news:%...
    Hi,

    I'd like to find out the control that caused a postback to be raised. Obviously this could simply done in a control event handler. I am not going to do this method and would like no references as to how to do it this way as I already know how.

    I know this may be getting into advanced or unheard of territory.

    I have some custom web user controls that are dynamically created at run time along with other controls. I can still add an event handler to these controls, but unfortunately the event handler wont fire until the controls are re-created on the postback, but I don't want the start-up code running on a post back, I need it to run in the event of the control that cuased the post back. This works fine for my other controls on the form that arn't generated, but will not for this user control, so I need an alternative.

    I need some indication in my page_load (or init) event that tells me that our user control has initiated the postback and to then run start up code.

    Are there any techniques out there that allow me to dig into the postback and discover what control or control type made the postback?

    Another solution I could add a client side handler that could set the value of a checkbox but due to the complexity of the user control I am not going to do that, as a post back could be initiated by a multiple number of events on different controls within the user control.

    Thats my question! Thanks..
    Dan, Dec 1, 2003
    #4
  5. Dan

    vMike Guest

    Are the control(s) within the form tags?
    "Dan" <> wrote in message news:%...
    the items do actually exist in the Request.Form collection...

    but are ""


    "vMike" <> wrote in message news:bq8kfb$6nl$...
    You should be able to add an eventhandler, but if you don't want to you can use Request.Form("__EVENTTARGET"). You must have a control on your form that renders the function __doPostBack(eventTarget, eventArgument) on your page. Many controls will put the function on your page. You could always put a dummy control like a linkbutton or something on your page to force the script to be rendered. Hope this helps.

    "Dan" <> wrote in message news:%...
    Hi,

    I'd like to find out the control that caused a postback to be raised. Obviously this could simply done in a control event handler. I am not going to do this method and would like no references as to how to do it this way as I already know how.

    I know this may be getting into advanced or unheard of territory.

    I have some custom web user controls that are dynamically created at run time along with other controls. I can still add an event handler to these controls, but unfortunately the event handler wont fire until the controls are re-created on the postback, but I don't want the start-up code running on a post back, I need it to run in the event of the control that cuased the post back. This works fine for my other controls on the form that arn't generated, but will not for this user control, so I need an alternative.

    I need some indication in my page_load (or init) event that tells me that our user control has initiated the postback and to then run start up code.

    Are there any techniques out there that allow me to dig into the postback and discover what control or control type made the postback?

    Another solution I could add a client side handler that could set the value of a checkbox but due to the complexity of the user control I am not going to do that, as a post back could be initiated by a multiple number of events on different controls within the user control.

    Thats my question! Thanks..
    vMike, Dec 1, 2003
    #5
  6. Dan

    bruce barker Guest

    then the postback was caused by a submit button (or image button). these postback by sending their name and value in form fields collection.

    -- bruce (sqlwork.com)

    "Dan" <> wrote in message news:#...
    the items do actually exist in the Request.Form collection...

    but are ""


    "vMike" <> wrote in message news:bq8kfb$6nl$...
    You should be able to add an eventhandler, but if you don't want to you can use Request.Form("__EVENTTARGET"). You must have a control on your form that renders the function __doPostBack(eventTarget, eventArgument) on your page. Many controls will put the function on your page. You could always put a dummy control like a linkbutton or something on your page to force the script to be rendered. Hope this helps.

    "Dan" <> wrote in message news:%...
    Hi,

    I'd like to find out the control that caused a postback to be raised. Obviously this could simply done in a control event handler. I am not going to do this method and would like no references as to how to do it this way as I already know how.

    I know this may be getting into advanced or unheard of territory.

    I have some custom web user controls that are dynamically created at run time along with other controls. I can still add an event handler to these controls, but unfortunately the event handler wont fire until the controls are re-created on the postback, but I don't want the start-up code running on a post back, I need it to run in the event of the control that cuased the post back. This works fine for my other controls on the form that arn't generated, but will not for this user control, so I need an alternative.

    I need some indication in my page_load (or init) event that tells me that our user control has initiated the postback and to then run start up code.

    Are there any techniques out there that allow me to dig into the postback and discover what control or control type made the postback?

    Another solution I could add a client side handler that could set the value of a checkbox but due to the complexity of the user control I am not going to do that, as a post back could be initiated by a multiple number of events on different controls within the user control.

    Thats my question! Thanks..
    bruce barker, Dec 1, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Srinivasa Raghavan Sethuraman
    Replies:
    0
    Views:
    554
    Srinivasa Raghavan Sethuraman
    Jun 30, 2004
  2. Guest
    Replies:
    2
    Views:
    2,010
    Steven Cheng[MSFT]
    Aug 18, 2005
  3. Abubakar
    Replies:
    10
    Views:
    718
    Gregory A. Beamer
    Jul 30, 2009
  4. Dan
    Replies:
    5
    Views:
    166
    bruce barker
    Dec 1, 2003
  5. Mike Malone

    Which control initiated post back

    Mike Malone, Feb 19, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    109
    Alvin Bruney [MVP]
    Feb 21, 2004
Loading...

Share This Page