473,322 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

how to fire an event programmatically?

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!
Nov 19 '05 #1
5 10330
Button1 triggers a postback. This means the server is busy processing the
postback. Now you want to fire another click event. But it is the client who
fires onclick events. This means you need another postback to communicate
the second onclick to the server. Is this what you mean by *actually fire*
the click event of Button2? Or you want to fake another onclick on the
server side?

Eliyahu

"Verde" <VF******@BeansAndTacos.net> wrote in message
news:u9**************@TK2MSFTNGP09.phx.gbl...
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!

Nov 19 '05 #2
just call the vent of button 2
button1_event(e,e)
{
bla bla
button2_event(null,null)
}

Nov 19 '05 #3
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
Nov 19 '05 #4
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

"Hans Kesting" <ne***********@spamgourmet.com> wrote in message
news:Og**************@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

Nov 19 '05 #5
I want to fake another .Click on the server side.
But I figured it out... see my response to Hans.

Thanks for your interest!


"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Button1 triggers a postback. This means the server is busy processing the
postback. Now you want to fire another click event. But it is the client
who
fires onclick events. This means you need another postback to communicate
the second onclick to the server. Is this what you mean by *actually fire*
the click event of Button2? Or you want to fake another onclick on the
server side?

Eliyahu

"Verde" <VF******@BeansAndTacos.net> wrote in message
news:u9**************@TK2MSFTNGP09.phx.gbl...
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!


Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kevin Ly | last post by:
Consider the test case below. The onmouseout event does NOT fire when my mouse/cusor is moved off the left side of the browser. It does if it is moved off the top, bottom, and the right side that...
2
by: Robbie | last post by:
Hi, I want to programatically fire an event. I have it working in IE, but Netscape won't work. What is the Netscape equivalent to, or a workaround for: document.myForm.myField.onchange(); ...
9
by: HJ | last post by:
Hi all, I notice that the Form_Dirty event does not fire in Access 2002 (SP-1) when the first character is typed into a new record. In previous versions of Access it does fire. For existing...
5
by: Carlo Marchesoni | last post by:
From an aspx page (A.aspx) I open another one (B.aspx - for table lookup). When the user selects an entry in B.aspx I would like to force a button's event in A.aspx to be fired. I guess the only...
2
by: Sam Miller | last post by:
Hi, I have a button event that won't fire. I left it on Friday and it worked fine. I came back in on Monday and it won't fire. I tried putting another button and just putting a...
4
by: Matt Fielder | last post by:
I have a control that the user is able to manually resize --- and it works great. The problem is I need to handle something when the control is done being resized, but not during the resize, so...
4
by: Ty Salistean | last post by:
So, here is a wierd question that we have been discussing for a bit now. Does an event fire even though nothing is subscribed to listen to the event? For instance, does the Click event of a...
19
by: Daniela Roman | last post by:
Hello, I try to fire an event under a button click event and maybe anybody can give a clue please. I have let's say a WEB grid with PageIndexChanged event: private void...
3
by: Crazy Cat | last post by:
Hi all, I am developing an asp.net 2.0 application in Visual Studio 2005. On my page I have a simple datalist that is bound programmatically to a collection of simple objects. On this page I...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.