how to avoid post-back on button (web control) click in asp.net 2.0?

L

loga123

Hi All,

I have a web page where I would like to do certain activities when user
click's a button.
I have used button web control on my page. Each time, I click this
button....page gets posted.
I don't want my page to do "post-back" when i click on button web
control.
is there any way to accomplish this?
Can anyone help me in this regard?

thanks
 
M

Mark Rae

I have a web page where I would like to do certain activities when user
click's a button.
I have used button web control on my page. Each time, I click this
button....page gets posted.
I don't want my page to do "post-back" when i click on button web
control.
is there any way to accomplish this?
Can anyone help me in this regard?

If you don't want your button to postback, that is presumably because it can
achieve everything it needs to do client-side i.e. with JavaScript...?

In which case, don't use an <asp:Button> control at all - simply use an HTML
button e.g.

<input type=button id=cmdHello value="Hello" onclick="alert('Hello');">
 
E

Edwin Knoppert

The HTML section in the toolsbox contains plain HTML controls including your
button.
No postbacks..
 
D

Darren Kopp

Are you wanting to post to a different page? If so, there is a
property on the button where you can specify where to post to. If you
are looking for something like javascript, you can use the HTML input,
or put onclick attribute as the javascript you want to do, followed by
"return false;" and i believe that will work for you.

HTH,
Darren Kopp
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

That doesn't prevent a post-back. It only prevents the code to be
executed when the post-back happens.
 

g4j

Joined
Apr 12, 2009
Messages
1
Reaction score
0
Thanks

The return false really stop the postback. I had the simllar problem in which I wanted to use a Web Control (custom look and feel, didn't want to write CSS again) but I didn't want to use it for postback. I just added the attribute like this:

Code:
''Visual Basic.Net
btnNoPostBackButton.Attributes.Add("OnClick", "DoSomething(); return false;")

This worked wonderfully for me. Thanks

God Bless!
 
Joined
May 15, 2009
Messages
1
Reaction score
0
g4j said:
The return false really stop the postback. I had the simllar problem in which I wanted to use a Web Control (custom look and feel, didn't want to write CSS again) but I didn't want to use it for postback. I just added the attribute like this:

Code:
''Visual Basic.Net
btnNoPostBackButton.Attributes.Add("OnClick", "DoSomething(); return false;")

This worked wonderfully for me. Thanks

God Bless!

Beautiful!! Thanks so much :)
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top