0

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

2

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

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.
0

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

0

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
}
answered Oct 16, 2019 at 8:49

Comments

-1

replace

OnClick="loginbtn_Click"

with

OnClick="loginbtn_Click()"
answered Aug 26, 2014 at 21:14

1 Comment

there is an error if i use logintbn_click() ----- Compiler Error Message: CS1501: No overload for method 'loginbtn_Click' takes 0 arguments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.