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

  • Thread starter Thread starter loga123
  • Start date Start date
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
 
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');">
 
write your code like thisin Page_load()


if(!Page.IsPostBack)
{

your code

}
 
You need to use javascript. Check the following
atlas.asp.net

Tasos
 
The HTML section in the toolsbox contains plain HTML controls including your
button.
No postbacks..
 
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
 
That doesn't prevent a post-back. It only prevents the code to be
executed when the post-back happens.
 

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

Back
Top