How to intercept an event in ASP.NET?

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

  1. #1

    Default Re: How to intercept an event in ASP.NET?

    You can override the RaisePostBackEvent method of the Page class.
    The first parameter sent to this method is the object that caused the
    postback.
    Remember to call MyBase.RaisePostBackEvent so the postback event gets raised
    correctly.

    Alternately, instead of the load event you could move your conditional code
    to the PreRender event , which happens after all the control events. So by
    then you'll know which control(s) caused the postback.

    --
    I hope this helps,
    Steve C. Orr, MCSD
    [url]http://Steve.Orr.net[/url]


    "Jon" <to_jon@hotmail.com> wrote in message
    news:e4b2505c.0308051326.4170a95e@posting.google.c om...
    > I'm new to event handling in ASP.NET and would like to intercept an
    > event in the standard Page_Load routine. Basically, I'd like to know
    > what user event trigerred the page load- the name of the button
    > pressed or other object involved. I know that the Page_Load sub is
    > passed 2 things: System.Object and System.EventArgs. Can I access
    > one of these to get the info?
    >
    > Is this possible... I also realize that I may be thinking of this the
    > wrong way conceptually.
    >
    > Thanks
    > Jon

    Steve C. Orr, MCSD Guest

  2. Similar Questions and Discussions

    1. How to intercept property changes in subclassed control?
      I've got an application that uses constants stored in XML files (see attached). The XML files are loaded into mx:Models and used as dataProviders on...
    2. Intercept when my control dropped on a WebForm
      Hi All! I need to intercept the event when my control dropped on a WebForm (or manually added by changin page's source HTML). I know about...
    3. HttpWebResponse intercept raw HTTP?
      For diagnostic and learning purposes, I would like to intercept and log the raw HTTP headers and content from a HttpWebResponse in a webservice. ...
    4. Usercontrol Postback - can i intercept Request
      Hi I have a site that creates a template file "default.aspx" and places usercontrols in it to display the pages. The beginrequest event redirects...
    5. WEBFORM: can I intercept Back and...
      Roby, HTTP is connectionless. Therefore, you have no way of intercepting client-side events from server-side code. Jim Cheshire Developer...
  3. #2

    Default Re: How to intercept an event in ASP.NET?

    Goto your CodeFront/Presentation Page ( Design Mode ) of your web page
    Double Click on the Button you want. This will take you to the CodeBehind
    page
    Type in your Button Handler Code
    private void Button1_Click(object sender, System.EventArgs e)

    {

    // type here what you want


    }


    "Jon" <to_jon@hotmail.com> wrote in message
    news:e4b2505c.0308051326.4170a95e@posting.google.c om...
    > I'm new to event handling in ASP.NET and would like to intercept an
    > event in the standard Page_Load routine. Basically, I'd like to know
    > what user event trigerred the page load- the name of the button
    > pressed or other object involved. I know that the Page_Load sub is
    > passed 2 things: System.Object and System.EventArgs. Can I access
    > one of these to get the info?
    >
    > Is this possible... I also realize that I may be thinking of this the
    > wrong way conceptually.
    >
    > Thanks
    > Jon

    MS News Guest

  4. #3

    Default Re: How to intercept an event in ASP.NET?

    Why not simply handle the event raised by the object which caused the
    postback? For instance, the Click event of a button, or SelectedIndexChanged
    of a DropDownList?

    --
    John Saunders
    Internet Engineer
    [email]john.saunders@surfcontrol.com[/email]


    "Jon" <to_jon@hotmail.com> wrote in message
    news:e4b2505c.0308051326.4170a95e@posting.google.c om...
    > I'm new to event handling in ASP.NET and would like to intercept an
    > event in the standard Page_Load routine. Basically, I'd like to know
    > what user event trigerred the page load- the name of the button
    > pressed or other object involved. I know that the Page_Load sub is
    > passed 2 things: System.Object and System.EventArgs. Can I access
    > one of these to get the info?
    >
    > Is this possible... I also realize that I may be thinking of this the
    > wrong way conceptually.
    >
    > Thanks
    > Jon

    John Saunders Guest

  5. #4

    Default Re: How to intercept an event in ASP.NET?

    That's a good point John- in short, I'd like to do something if the
    form has been posted through ALL types of events except for one or two
    specific events. It seems easier to detect that in the Page_Load
    rather than add code to every possible event for every object on the
    page. Hope that's more clear.


    "John Saunders" <john.saunders@surfcontrol.com> wrote in message news:<OJiuU35WDHA.1644@TK2MSFTNGP10.phx.gbl>...
    > Why not simply handle the event raised by the object which caused the
    > postback? For instance, the Click event of a button, or SelectedIndexChanged
    > of a DropDownList?
    >
    > --
    > John Saunders
    > Internet Engineer
    > [email]john.saunders@surfcontrol.com[/email]
    >
    >
    > "Jon" <to_jon@hotmail.com> wrote in message
    > news:e4b2505c.0308051326.4170a95e@posting.google.c om...
    > > I'm new to event handling in ASP.NET and would like to intercept an
    > > event in the standard Page_Load routine. Basically, I'd like to know
    > > what user event trigerred the page load- the name of the button
    > > pressed or other object involved. I know that the Page_Load sub is
    > > passed 2 things: System.Object and System.EventArgs. Can I access
    > > one of these to get the info?
    > >
    > > Is this possible... I also realize that I may be thinking of this the
    > > wrong way conceptually.
    > >
    > > Thanks
    > > Jon
    Jon Guest

  6. #5

    Default Re: How to intercept an event in ASP.NET?

    "Jon" <to_jon@hotmail.com> wrote in message
    news:e4b2505c.0308061153.754eb3ed@posting.google.c om...
    > That's a good point John- in short, I'd like to do something if the
    > form has been posted through ALL types of events except for one or two
    > specific events. It seems easier to detect that in the Page_Load
    > rather than add code to every possible event for every object on the
    > page. Hope that's more clear.
    It's clearer.

    I would put that common code in a subroutine and call it from the handler of
    each event where you want that common stuff done. You should not have any
    one part of your code whose job it is to know about all the possible events
    your form may generate now or in the future. What if form changes
    substantially? Instead, for each event, handle that event and do what's
    appropriate because of the event having taken place.

    If you wind up with common code amongst the event handlers, yank it out into
    a subroutine. For instance, I commonly need to display an error message in a
    status label. I yanked that out into a SetStatus subroutine. I call it from
    many separate events.

    --
    John Saunders
    Internet Engineer
    [email]john.saunders@surfcontrol.com[/email]


    John Saunders 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