I have a JavaScript code and an asp.net button control , javascript code is working fine but the asp.net button is not working for that js script
<asp:Button ID="loginbtn" CssClass="btn-glow primary login" OnClientClick="abc(); return false;" runat="server" Text="log in" OnClick="loginbtn_Click" />
asked Aug 26, 2014 at 21:07
4 Answers 4
Because you have return false
in your OnClientClick
. Remove it an the button will post back.
answered Aug 26, 2014 at 21:09
Sign up to request clarification or add additional context in comments.
1 Comment
mgmedick
Yes this ^ the client side code runs first, so your onClientClick is running before your OnClick, thus preventing the post back, because you're returning false.
please change the code like this
<asp:Button ID="loginbtn" OnClientClick="abc();" runat="server" Text="log in" OnClick="loginbtn_Click"/>
function abc() {
alert("Hi"); //put your code here
return false;
}
or
function abc() {
alert("Hi"); //put your code here
}
both will work.
answered Oct 16, 2019 at 8:41
Comments
Convert your asp.net button to input button to prevent callback and make an ajax function call.
<input type="button" class="btn-glow primary login" onClick="abc()"/>
function abc(){
//ajax call
}
Comments
replace
OnClick="loginbtn_Click"
with
OnClick="loginbtn_Click()"
answered Aug 26, 2014 at 21:14
1 Comment
user3617749
there is an error if i use logintbn_click() ----- Compiler Error Message: CS1501: No overload for method 'loginbtn_Click' takes 0 arguments
lang-js