I'm going to do my best here to assume what you are referring to and what
you are try to do.  First, when you say "I have written a HttpModule and
am calling a method on context.PreRequestHandlerExecute" I am assuming you
are referring to adding your own event handler to the HttpApplication
PreRequestHandlerExecute event using the instance passed in to your Init
method.  One thing I'm not quite sure about is by what time in the ASP.NET
life cycle do you need to know what control caused the post back.  You can
use the PreRequestHandlerExecute event but will cause you a little more
work and require you to have standard naming of buttons.


Assume just before the Click event handler is OK (Page Load has already
fired):

In a Page base class that all of your .aspx pages will inherit from,
override the RaisePostBackEvent method.  Here you can choose whether to
have the "click" event handler actually fire.  The nice thing about this
method is that it provides an instance to the Control that caused the
postback, button or link button.  After doing whatever it is you need to
do, just call base.RaisePostBackEvent(sourceControl, eventArgument); to
fire the click event or don't call it to skip the click event.  This is
the best option.


Assume before the Page Load event is required:

Here you are not a whole lot better than handling it at the
PreRequestHandlerExecute event unless the postback you care about only
comes from buttons and not link buttons.  If you are dealing only with
buttons, override the RegisterRequiresRaiseEvent method in a base page
class.  This method is fired before the page load and provides an instance
to the control that caused the postback.  Problem here is that the link
buttons use the __EVENTTARGET to indicate that they caused the postback.
So in order to handle the link button before the page load you will need
to investigate the value of the __EVENTTARGET (probably no guarantees it
will always stay that name) request item in the OnInit method.


Assume in the PreRequestHandlerExecute event handler is required:

Here you handle the link buttons the same as in the OnInit and you will
have to have a consistent name for your buttons so you can inspect whether
that item is in the request.  One thing to keep in mind regarding
inspecting the request for button names is that when you have controls on
a page, the name of the button will be ContainerControlID:MyButtonID or
nested Container1ID:Container2ID:...:MyButtonID.

Chad

On Fri, 22 Aug 2003 18:05:26 +0530, Sujay Suresh Maheshwari
<[EMAIL PROTECTED]> wrote:

>Hi Group,
>
>
>
>I have written a HttpModule and I am calling a method on
>context.PreRequestHandlerExecute
>
>
>
>Now this method will be called on all page load. Can I know the event
>which called this page load. Rather if a user presses an Add button, can
>I know that an add button is clicked.
>
>
>
>May be not in this method, but can I know the event which is generated
>before actually the event function in my code behind gets called.
>
>
>
>Basically I want a centralized method which is called throughout
>application before actually the code behind code getting executed. And I
>don't want to called this method everywhere in my code behind pages.
>
>
>
>Regards,
>
>
>
>Sujay
>
>
>===================================
>This list is hosted by DevelopMentor�  http://www.develop.com
>NEW! ASP.NET courses you may be interested in:
>
>2 Days of ASP.NET, 29 Sept 2003, in Redmond
>http://www.develop.com/courses/2daspdotnet
>
>Guerrilla ASP.NET, 13 Oct 2003, in Boston
>http://www.develop.com/courses/gaspdotnet
>
>View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
NEW! ASP.NET courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to