Write return statement while calling javascript. So, whenever javascript will return false Button1 will not allow to submit form.
Try this:
HTML:
<asp:Button ID="Button1" runat="server" Text="My Button" OnClientClick="return MyFunction();" />
Javascript:
function MyFunction()
{
return false;
}
[Edit 1]
Since you are passing the parameters in function, you can add the attributes to button from code behind from
Page_Load
event. Try this in your
Page_Load
event:
C#:
Button1.Attributes.Add("onclick", "return validatebutton1('" + txtUserName.ClientID + "', '" + txtPassword.ClientID + "');")
Let you javascript be the same.
HTML:
<asp:Button ID="Button1" runat="server" Text="My Button" />
--Amit