Solved

How do I get my javacript (onclientclick) to stop the postback of my ASP.NET page?

Posted on 2009-07-01
3
1,212 Views
Last Modified: 2013-12-17
I have a javacript function associated with the OnClientClick of an ASP.Net button.  I also have the OnClick associated with a server-side function.  My OnClientClick code evaluates values on the page and returns true or false.  If I return false I don't want the page to postback. Even if I return false the page posts back.

Do I need to hand code the ASP.NET postback in the javacript and remove the OnClick of the ASP.NET button?
0
Comment
Question by:Bruce
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
j_s_kelley earned 500 total points
ID: 24754599
Make sure your return false in the actual control markup.  You can't do it in the javascript function.

<asp:Button OnClientClick="javascript:return CheckMyData();">< /asp:Button>

Send your code and I will look at it and try to tell where you need the return.
0
 
LVL 1

Author Closing Comment

by:Bruce
ID: 31598779
That was it!  Thanks for the quick response.
0
 
LVL 4

Expert Comment

by:j_s_kelley
ID: 24754757
Hey, got a better example for you.  In this example, we have a Server side button that closes a dialog window.  It is Server side so we can control how it is streamed down but don't care about the server responding to the click, we just want to close the window.  

<asp:Button ID="btnCancel" runat="server" class="button" Text="Cancel" OnClientClick="javascript:window.close();return false;" />

See how the return false; is in the actual markup of the button.  This will prevent a post back.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Add Rows on a Table 8 51
Jquery Calculation 3 40
How to strip HTML from this JS code using regex 29 44
What is GIS method of Geometry data type? 6 33
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question