Ramya S

Ramya S

  • NA
  • 79
  • 8.1k

onclientclick event

Jun 24 2016 3:24 AM
Hi,
  
here is my aspx code: 
 
<div align="center" style="display:table;margin:auto"><asp:TextBox runat="server" ID="txtSearch" CssClass="search" placeholder="Enter Stock Number(or) Stock Description.." style="margin-left: 0" Width="367px" ForeColor="#00" ></asp:TextBox>
 
<asp:Button runat="server" ID="btnSearch" Text="Search" OnClick="btnSearch_Click" OnClientClick="displayalert()" ForeColor="#003c71"/></div>
</div>
 
itemtemplate in grid view:
 
<asp:TextBox runat="server" ID="txtQnty" Text='<%#Eval("Quantity") %>' ForeColor="#003c71"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
 
<asp:TemplateField HeaderText="Update">
<ItemTemplate>
<asp:Button runat="server" ID="btnUpdate" Text="Update" OnClientClick="updatealert()" OnClick="btnUpdate_Click" ForeColor="#003c71"></asp:Button>
</ItemTemplate>
</asp:TemplateField>
 
my javascript code is:
 
<script type="text/javascript">
function displayalert()
{
if(document.getElementById("txtSearch").value == "")
{
alert("Enter stock number or stock description!");
return false;
}
}
</script>
<script type="text/javascript">
function updatealert()
{
if (document.getElementById("txtQnty").value == "") {
alert("Enter Quantity!");
return false;
}
else {
alert("Update Successfully!")
return true; 
}
}
</script>
<script type="text/javascript">
 
 why OnClientClick="updatealert()" is not working and displayalert() showing alert message but redirecting to error message!
 
 

Answers (3)