Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I have a button where I want to do some javascript validation before is runs its OnClick server code. My problem is that even though the javascript function returns false the btnAdd_Click code still gets executed.

 

Javascript

 
function confirmAdd()
{
var cmbOrder=document.getElementById("cmbOrder");
var txtInvoiceNumber=document.getElementById("txtInvoiceNumber");
if (cmbOrder.value.length > 0 && txtInvoiceNumber.value.length == 0)
{
exit = confirm("Are you sure that this order has not been invoiced? (OK=Yes Cancel=NO)")

if (exit == true)
{
return true; //add order
}
else
{
return false; //dont add order
}
}
else
{
return true; //add order
}
}

 

HTML code

 
<asp:Button ID="btnAdd" runat="server" Width="100" Text="Add Order" CausesValidation="True" OnClick="btnAdd_Click" TabIndex="20" />

 

Page Load

 btnAdd.Attributes.Add("onclick","javascript:confirmAdd();")

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...