0

well I've never used jQuery on ASP.NET only PHP and now I have this problem because I have an input type button and with jQuery I have a click function but it's not firing. If anyone knows why and how this could be fixed. This is my code:

    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.js">

        $(document).ready(function(e) {
            var usuario = $("#tbUsername").text();
            var password = $("#tbPassword").text();

            var jsonInfo = "usuario:" + usuario + "," + "password:" + password;

            $("#btLogin").click(function () {

                alert('Click');

            });

            function _throwError(XMLHttpRequest, textStatus, errorThrown) {
                alert("Request: " + XMLHttpRequest.toString() + "Status " + textStatus);
            }

            function _onSuccess(data, Status, jqXHR) {
                if (data == 'authenticated') {
                    alert('User authenticated');
                }
                else {
                    alert('User and password do not match');
                }
            }
        });
    </script>
    <style type="text/css">

    </style>
    </asp:Content>  

And this is my ASP.NET code, it's all on the client side:

    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        Please login to continue:
    </h2>

    <table>
        <tr>
            <td><label>Username: </label></td><td><input id='tbUsername'></td>
        </tr>
        <tr>
            <td><label>Password: </label></td><td><input id='tbPassword'></td>
        </tr>
        <tr>
            <td colspan="2"><input type="button" value="Login" id="btLogin"/></td>
        </tr>
    </table>

    <div id="resultado"></div>
    <p>

    </p>
</asp:Content>

Thanks and regards.

1 Answer 1

1
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.js" >
</script>

 <script type="text/javascript">
        $(function () {
            $("#btLogin").click(function () {

                alert('Click');

            });
        });

    </script>
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you that was it, I forgot that important part. Awesome @serbasi
Im not sure, but it did run in normal HTML, I tried it on Sublime as a normal HTML document and it did work.

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.