What Control Caused the PostBack?

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default What Control Caused the PostBack?

    Is there any way to dynamically get the name of the control that caused the
    postback? Since SmartNav is not working for me I'm trying to implement a way
    to scroll to the control that caused the post back so the user does not have
    to scroll all the time.

    I got the script working great and everything else, but I want to be able to
    tell the name of the control that posted back. That way we don't have to
    hard code much at all.

    This is what I have implemented so far:

    Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles MyBase.PreRender

    ' automatically scroll to the object that posted back (if applicable)

    If Page.IsPostBack > 0 Then

    RegisterStartupScript("scroll", "<script language=javascript>" +
    _scrollToObjectPath + _scrollToObjectName + ".scrollIntoView();</script>")

    End If



    End Sub


    Thanks in advance,
    - Jeff


    Jeff Voigt Guest

  2. Similar Questions and Discussions

    1. Determining What Control Caused The PostBack
      I have a DataList that I was having trouble getting the events for. After a bit of help, I realized that I needed to put the databinding inside an...
    2. help with postback-less calendar control.
      hi, I need to create a Calendar control that does not do postback when a date is selected...any ideas on how to do this thanks in advance...
    3. Did my control caused the postback
      You want to know it on Page or in the control itself? If your control implements IPostBackEventHandler, you could override RaisePostBackEvent on...
    4. How to determine Control that caused Postback?
      My event target is blank. Why would it be blank? I put a value in for the CommandArgument and CommandName. I am using the following syntax......
    5. How to see what caused PostBack
      I have few buttons on a page. In Page_Load I would like to determine which one caused post back. How to do?
  3. #2

    Default Re: What Control Caused the PostBack?

    "Jeff Voigt" <jeffrey.voigt@djj.state.fl.us> wrote in message
    news:ezpBSPdXDHA.2352@TK2MSFTNGP12.phx.gbl...
    > Is there any way to dynamically get the name of the control that caused
    the
    > postback? Since SmartNav is not working for me I'm trying to implement a
    way
    > to scroll to the control that caused the post back so the user does not
    have
    > to scroll all the time.
    Jeff, you could look at the value of the __EVENTTARGET hidden field via
    Request.Form["__EVENTTARGET"].

    You should note that although this will work in many cases, it won't work
    for all. ASP.NET searches the control tree looking for a control with its
    ClientID equal to __EVENTTARGET and implementing IPostBackEventHandler. If
    found, it will pass __EVENTTARGET and __EVENTARGUMENT to this controls
    RaisePostBackEvent method.

    Usually, __EVENTTARGET is the ClientID of a single control in a single place
    on the page. But a composite control may have many child controls which can
    post back, and __EVENTTARGET may only name a single hidden field located in
    front of all of those child controls. The composite control might then use
    __EVENTARGUMENT to distinguish which child control caused the postback, but
    you would be unable to do so.

    Another issue would be the case where a button causes the postback, but that
    it is "clicked" via its accessKey attribute. This button might not be
    anywhere near where the user was working when he pressed the access key.

    Is there anything in the DOM which would give you a better idea of "what
    part of the window is visible right now"? If so, you might capture onsubmit
    and cause that information to be sent to the host, which could send it back
    to the page in the response. Code in the onload handler on the page might
    then be able to restore that information.
    --
    John Saunders
    Internet Engineer
    [email]john.saunders@surfcontrol.com[/email]


    John Saunders Guest

  4. #3

    Default Re: What Control Caused the PostBack?

    You may be able to get it from Request.Form("__EVENTTARGET"), but AFAIK
    that's only generated by asp.net if one of your controls, such as a
    combobox, has it's AutoPostBack property set to True. I'm not 100% sure on
    that.

    "Jeff Voigt" <jeffrey.voigt@djj.state.fl.us> wrote in message
    news:ezpBSPdXDHA.2352@TK2MSFTNGP12.phx.gbl...
    > Is there any way to dynamically get the name of the control that caused
    the
    > postback? Since SmartNav is not working for me I'm trying to implement a
    way
    > to scroll to the control that caused the post back so the user does not
    have
    > to scroll all the time.

    eruess Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139