The short answer, as I eventually figured out is this:
tmpMyButton.RaisePostBackEvent("click");
FWIW: The reason I need to do this is that I'm using a 3rd party component
that implements its own .Click event that is NOT cancellable. Additionally,
this component does not trigger client-side control validation. My solution
is to implement a plain old <asp:ImageButton> to trigger the postback
(rather than using the 3rd party component). This gets the validation to
happen. On the server I then handle the ImageButton's click event. During
that event procedure I do more sophisticated validation and ensure that all
data required for the 3rd Party component is present. If it is, I then
programmatically instantiate the 3rd party component and fire its click
event procedure. Remember it's not cancellable - so rather than getting into
it and wishing I could cancel it if runtime conditions aren't right, I
verify the runtime conditions (in the asp:ImageButton's click event
procedrue) before even firing the 3rd party component's click event; thereby
having the same effect as cancelling it. Now, you're probably thinking this
is all fine and well but that I still don't have to fire the event (via
tmpMyButton.RaisePostBackEvent("click");) and could instead call another
method. Not true -- because the 3rd party component *always* does something
internally (i.e., I don't know how it does it) as part of its click event
procedure *after* all of my code in its [click event procedure] has run: It
POSTs data to the vendor's Web site and redirects my user to their site. If
I don't want my user to go to the vendor's site under some runtime
conditions, then I'd have to cancel the click event. But because I can't
cancel it I have to make sure it never gets fired under those conditions.
But when conditions are right I do need to ensure that my users and data get
transferred - and because the component does that as part of it's click
event I need to fire that click event (running my own code doesn't get the
user to the 3rd Party site). So, at the end of the day I get (1) client side
validation and (2) the functional equivalent of a cancellable event and (3)
leverage a 3rd party component's existing functionality to transfer
user+data -- when the component does not support the first two of these
things.
-V
[quoted text, click to view] "Hans Kesting" <news.2.hansdk@spamgourmet.com> wrote in message
news:Ogrp0FfuFHA.3500@TK2MSFTNGP09.phx.gbl...
> Verde wrote:
>> This is admittedly an apparently odd request... but please indulge me
>> if you don't mind:
>>
>> Suppose I have two <asp:Button.../> on a page (Button1 and Button2).
>> User clicks Button1 and triggers a PostBack. How can I then fire the
>> click event of Button2 during the same PostBack?
>>
>> I know this seems like a totally bad situation I'm creating out of
>> naiveity. But please indulge. It would save me from having to provide
>> a lengthy explanation for why I'm interested in doing this.
>>
>> Please note - I want to *actually fire* the click event of Button2. It's
>> not enough to simply run code in some independent method that
>> could get called from either button's click event procedure.
>>
>> Thanks!
>
> What do you think is the difference between "actually fire" the click
> event and call a method?
>
> For C# code is generated like: Button1.Click += new ClickEventHandler(...)
> You could try and add the handler for the Button2.Click also to
> Button1.Click
> (so Button1.Click has two handlers and the Button2 handler is called by
> both clicks)
> Do this in the Page_Load so you don't need to alter the generated code.
>
> Hans Kesting
>
>