• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2865
  • Last Modified:

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

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
P1ST0LPETE
Asked:
P1ST0LPETE
2 Solutions
 
glcumminsCommented:
Try including the return in the link definition:
    OnClientClick="javascript:return CheckEmailBeforeSchedule()" />

Open in new window

0
 
gemailjCommented:
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
 
P1ST0LPETEAuthor Commented:
Works perfect now, Thanks!!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now