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" />

4 Answers 4

2

Because you have return false in your OnClientClick. Remove it an the button will post back.

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.

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
}

Comments

-1

replace

OnClick="loginbtn_Click"

with

OnClick="loginbtn_Click()"

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

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.