asp.net 2.0 button with return false javascript STILL POSTING BACK!!!

I have 4 hours in this and I don't get it. I have tried every example. Is there not a way to stop post the form by returning false from javascript?  even this doesn't work...
function thisFunc()
{  return false; }
It is executing but does not stop the post. Code below
Server side: 
 Button1.OnClientClick = "return doPost();"; 
 
Client side:
 <script type="text/javascript">
     	 function doPost()
	   {
           	         return false      
                          }

Open in new window

ecsmooreAsked:
Who is Participating?
 
ITHelper80Connect With a Mentor Commented:
Someone said here was the fix.

<asp:Button ID="btnDELETE" runat="server" OnClick="btnDELETE_Click" Text="Delete" OnClientClick="if(confirm('Selected records will be deleted?')==false){event.returnValue=false;return false;}else{return true;}" />

Please let us know if you get it fixed...Im sure I will see this again in the future.
0
 
ITHelper80Commented:
Have you set the asp button postback property to false?

<asp:button postback="false"/>
0
 
ecsmooreAuthor Commented:
Not sure what you mean? There is not Postback property. In some .NET controls there is Autopostback but not on the button.  ???
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
ITHelper80Commented:
Sorry, Try this.

Its using an ASP button and should work better for you.


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <script language=javascript type="text/javascript">
        function myOnClick() {
            //perform some other actions...
            return false;
        }
    </script>
    <title>Untitled Page</title>
</head>
<body bgcolor="buttonface" bottommargin="0" topmargin="0">
    <form id="form1" runat="server">
    <div>
<asp:Button ID="btnyours" runat="server" Text="Work Darnit" OnClientClick="return myOnClick()" />
    </div>
    </form>
</body>
</html>

Open in new window

0
 
ecsmooreAuthor Commented:
This is what is so strange. It is exactly how I started this out and it did not work. I have tried this and many other implementations and nothing stops the postback.  Could it have someting to do with Masterpages, which is another piece to this environment?
I tried just as you have demonstrated with no code in javascript other than return = false; and it still posts back.  Any idea what I have wrong?
0
 
ecsmooreAuthor Commented:
I just made a new page, fresh out of the box with your suggestion, and added this code behind and it posts back:
Web page (your code)
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <script language=javascript type="text/javascript">
        function myOnClick() {
            //perform some other actions...
            return false;
        }
    </script>
    <title>Untitled Page</title>
</head>
<body bgcolor="buttonface" bottommargin="0" topmargin="0">
    <form id="form1" runat="server">
    <div>
<asp:Button ID="btnyours" runat="server" Text="Work Darnit" OnClientClick="return myOnClick()" />
    </div>
    </form>
</body>
</html>

Code behind:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class NoPostback : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            Response.Write("not fixed yet");
        }
       
    }
}
0
 
ITHelper80Commented:
Im not sure. What is the code behind the button?

Have you tried to also add onclick="return false" along with what I posted above?
0
 
ITHelper80Commented:
It works for me...

One minor thing.

Change script language=javascript  to script language="javascript"
0
 
ITHelper80Commented:
Here is the working code in C#
<%@ Page Language="C#" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<script runat="server">
 
    protected void btnyours_Click(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            Response.Write("not fixed yet");
        }
    }
</script>
    <script language="javascript" type="text/javascript">
        function myOnClick() {
            //perform some other actions...
            return false;
        }
    </script>
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Button ID="btnyours" runat="server" Text="Work Darnit" OnClientClick="return myOnClick()" OnClick="btnyours_Click"/>
 
    </div>
    </form>
</body>
</html>

Open in new window

0
 
ecsmooreAuthor Commented:
this is crazy... the code above... copied directly in to my VS 2008.  It posts pack and displays
"not working yet".

You are saying it does not do this on your machine?
0
 
ITHelper80Commented:
thats correct....i removed the onclick function from the button and tested it again, sure enough i saw "not fixed yet", i added the function back and tried it again. No text....

that is strange.

what browser are you testing in.
0
 
ITHelper80Commented:
Ive tried this in both VWD 2005 and 2008 and it works perfectly
0
 
ecsmooreAuthor Commented:
IE 7.. GOING TO TRY FF now
0
 
ITHelper80Commented:
Just as an FTI you may need to enable javascript for IE 7...I read its turned off by default
0
 
ecsmooreAuthor Commented:
I will check that but I see it is working and stepping thru just fine. It is just ignoring the return = false:

Your code works fine in FF
0
 
ecsmooreAuthor Commented:
javascript is enabled in my IE7 environment .... don't get it.
0
 
ecsmooreAuthor Commented:
well I just did a search on IE7 and this problem... Haven't read it yet but here is the first item in the list
http://forums.asp.net/t/1161858.aspx
0
 
ITHelper80Commented:
Oh just to make it even more strange I am running IE7 too....=)
0
 
ecsmooreAuthor Commented:
Yes... I just read a few blogs and big argument cuz it works on about 50% of situations so the ones it works on, of course, say to the others, "Yes it does work"  blah blah....
Going to try that fix now.
0
 
ecsmooreAuthor Commented:
Honestly, I have been on this since 1PM with a break for dinner. This solution works.
0
 
ecsmooreAuthor Commented:
Thanks alot for hanging in there with me. I was getting pretty frustrated.
0
 
ITHelper80Commented:
NP, glad we could get it going. I know how frustrating this stuff can get.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.