Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Creating a Button that is type="button" and does not call __doPostBack

Reply
Thread Tools

Creating a Button that is type="button" and does not call __doPostBack

 
 
Nathan Sokalski
Guest
Posts: n/a
 
      01-11-2010
I want to create a Button that does not do a postback (I simply want to use
it for JavaScript). Some of the ways I know of to do this are:

1. Include "return false;" in the OnClientClick property. However, if
UseSubmitBehavior is set to True, it is type="submit", and if
UseSubmitBehavior is set to False, onclick still includes __doPostBack even
though it doesn't get called
2. Use an HtmlButton control. However, I would like to be able to use a
Button control.

Are there any ways to create a Button that does not do a postback? Thanks.
--
Nathan Sokalski
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.nathansokalski.com/


 
Reply With Quote
 
 
 
 
Gregory A. Beamer
Guest
Posts: n/a
 
      01-11-2010
"Nathan Sokalski" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> Are there any ways to create a Button that does not do a postback?


Use an HtmlControl instead of a server control and make sure you do not
set runat="server" is your best option. I am not sure why you do not
want to do this, as it is the best option when you do not want a
postback.

If absolutely MUST neuter an ASP.NET server control button, then do
something like:

<asp:Button ID="ButtonName" runat="server" Text="Click for JavaScript"
OnClientClick="return functionName()" />

You then have to ensure the function returns false:

<script type="text/javascript" language=javascript>

function functionName() {
alert('Look ma, no server script!');
return false;
}

</script>


The return false effectively neuters the button.

Another option is to subclass the button server control and neuter it.
It will end up with nearly identical code to the HtmlControl, however.
But it will retain some of the "goodness" of an button server control.

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
__dopostback only does what I want after row 8 Arch ASP .Net 2 08-12-2012 06:26 PM
Creating a Button that is type="button" and does not call __doPostBack Nathan Sokalski ASP .Net Web Controls 1 01-11-2010 03:57 PM
call __doPostBack from javascript method not working as expected SteveSu ASP .Net 2 11-08-2005 07:03 AM
__doPostBack manual call =?Utf-8?B?QUpQ?= ASP .Net 0 08-20-2004 06:03 PM



Advertisments