Click here to Skip to main content
15,886,678 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in javascript validation my button shows alert msg for error . at the same time it goes into code behind page ,But not at all time ,sometimes it happened.in javascript function i gave return false statement .

how can i solve this ?

Help me?

XML
<asp:imagebutton id="ImageButton1" imageurl="~/Images/images/btn-search.jpg" runat="server" onclick="Submitownerid_Click" onclientclick="return OwnerIDvalidation();" xmlns:asp="#unknown" />

JavaScript
function OwnerIDvalidation() {
       var City = document.getElementById("<%=ddldropcity.ClientID%>").value;
       if (City == "Select City") {
           alert("City has to be Select");
           document.getElementById("<%=ddldropcity.ClientID%>").focus();
           return false;
       }
       return true;
}

C#
protected void Submitownerid_Click(object sender, ImageClickEventArgs e)
{

    Cityname = "Select City";
    Owner_ID = txtownerid.Text;
    USERName = string.Empty;
    CustomerActivatedStartdate = string.Empty;
    CustomerActivatedEnddate = string.Empty;
    GetOwnerDetailsByownerid(Owner_ID);
    //txtName.Text = "";

}
Posted
Updated 27-Jan-12 3:51am
v3
Comments
[no name] 27-Jan-12 8:29am    
Since we can't read minds, maybe you should post some of the code you are using.
Anuja Pawar Indore 27-Jan-12 9:05am    
What you are using ...elaborate
Manfred Rudolf Bihy 27-Jan-12 9:51am    
Moved code from non-solution to OP's question.

1 solution

use
C#
return false;

after showing alert message
 
Share this answer
 
v2
Comments
priya from Madras 27-Jan-12 10:29am    
alreay given , but this problem is sometimes only

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900