[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

JavaScript "return false" not stopping postback on asp:LinkButton click

Posted on 2008-10-02
3
Medium Priority
?
2,847 Views
Last Modified: 2012-06-27
I've got some simple JavaScript that fires on a asp:LinkButton click to mare sure certain TextBoxes on the from are not null before being sent to the server.  The JavaScript is being fired, displaying a popup prompt to the user if a textbox is empty, however the JavaScript "return false" is not stopping the postback/OnClick events from firing.  Please advise.  Attached is the code.

Thanks,

Pete
*****************
    ASP:
*****************
<asp:LinkButton 
    ID="linkScheduleEmail" 
    runat="server" 
    Text="Schedule"
    OnClick="Email_ScheduleDelivery" 
    CssClass="Link-Black" 
    OnClientClick="javascript:CheckEmailBeforeSchedule()" />
<asp:LinkButton 
    ID="linkEmailSend" 
    runat="server" 
    CssClass="Link-Black" 
    Text="Send Now" 
    OnClick="Email_Send" 
    OnClientClick="javascript:CheckEmailBeforeSend()" />
 
 
*****************
   JavaScript:
*****************
//<!--
 
function CheckEmailBeforeSend()
{
    var tbSendTo = document.getElementById('ctl00_ContentPlaceHolder1_tbEmailTo');
    var tbSendSubject = document.getElementById('ctl00_ContentPlaceHolder1_tbEmailSubject');
    
    if(tbSendTo.value == "")
    {
        alert("ERROR: No Recipient Address Specified!");
        return false;
    }
    else if(tbSendSubject.value == "")
    {
        alert("ERROR: No Subject Defined!");
        return false;
    }
}
 
function CheckEmailBeforeSchedule() 
{
    var tbScheduleTo = document.getElementById('ctl00_ContentPlaceHolder1_tbEmailTo');
    var tbScheduleSubject = document.getElementById('ctl00_ContentPlaceHolder1_tbEmailSubject');
    var tbScheduleDate = document.getElementById('ctl00_ContentPlaceHolder1_tbEmailDate');
    
    if(tbScheduleTo.value == "")
    {
        alert("ERROR: No Recipient Address Specified!");
        return false;
    }
    else if(tbScheduleSubject.value == "")
    {
        alert("ERROR: No Subject Defined!");
        return false;
    }
    else if(tbScheduleDate.value == "")
    {
        alert("ERROR: No Schedule Date Assigned!");
        return false;
    }
}
 
//-->

Open in new window

0
Comment
Question by:P1ST0LPETE
[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
3 Comments
 
LVL 24

Accepted Solution

by:
glcummins earned 1400 total points
ID: 22625921
Try including the return in the link definition:
    OnClientClick="javascript:return CheckEmailBeforeSchedule()" />

Open in new window

0
 
LVL 5

Assisted Solution

by:gemailj
gemailj earned 600 total points
ID: 22626001
return has no effect without using return before calling the method so you have to use return like this
OnClientClick="javascript:return CheckEmailBeforeSend()"

Open in new window

0
 
LVL 10

Author Closing Comment

by:P1ST0LPETE
ID: 31502445
Works perfect now, Thanks!!!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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…
Suggested Courses

650 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