Can a web control's postback be blocked?

G

Geoff

I know how to add a client side event event handler to a webcontrol button
using Attributes.Add, which gives me both client side and server side
events. Sometimes I need to only do the client side event and not do the
postback to the server at all. Is there a way to block the postback
altogether? The obvious thing would be to use a HTML button that only has
client side events, but then I would have a problem when I do need the
server side event.

Much obliged,
Geoff.
 
S

Sambathraj

Hi,
The post back to server will not happen if the client side function you are
calling in OnClick returns false. This will stop event bubling
Regards
Sambathraj
 
B

billmiami2

I'm not totally clear on what you're doing, but you could perhaps do
the following:

*Add both an HTML button and a webcontrol button to the page, but set
the visible property of the webcontrol button to false so that it can't
be clicked directly by the user.

*In your client side click handler for your HTML button, force a
postback from the webcontrol button by calling

__doPostBack('webcontrolbuttonid','');

Passing the id of the web control button as a parameter. This will
kick of the server side event handler for your web control button. You
can also pass additional parameters in the second argument (I left it
empty) and pick them up in the page with

Request.Form("__EVENTARGUMENT")

although you may not need it here. I'm assuming that in your client
side event handler for the HTML button, you would determine whether or
not you should be firing the server side handler and do so when it
makes sense to do so.

Bill E.
Hollywood, FL
 
G

Geoff

Thanks, that did the trick.

Geoff.

Sambathraj said:
Hi,
The post back to server will not happen if the client side function you
are calling in OnClick returns false. This will stop event bubling
Regards
Sambathraj
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top