asp.net - Beginners jQuery issue -


i have experience javascript, complete noob when comes jquery. i'm trying add real simple click event handler return time. i'm not receiving errors in console nothing happens when button clicked (i added console.log purely testing purposes). imported entire bootstrap package through nuget, believe have complete jquery library. there else i'm missing? in advance!

<%@ page title="" language="c#" masterpagefile="~/site.master" autoeventwireup="true" codebehind="jquery.aspx.cs" inherits="garrettpenfieldunit10.webform2" %> <asp:content id="content1" contentplaceholderid="head" runat="server"> </asp:content> <asp:content id="content2" contentplaceholderid="contentplaceholder" runat="server">     <h1>jquery page</h1>     <p><asp:label id="labeljq" runat="server" text="click button!"></asp:label></p>     <asp:button id="buttonjq" runat="server" text="update time!"/>      <script src="scripts/jquery-1.9.1.js"></script>     <script type="text/javascript">         $('#buttonjq').click(function () {             var d = new date();             document.getelementbyid(labeljq).innerhtml = d.tolocaletimestring();             console.log('wubba lubba dub dub!');         });     </script> </asp:content> 

if inspect button in browser, suspect you'll find doesn't have id="buttonjq", because id of server control isn't (by default) client-side id.

you have @ least 3 options:

  1. add clientidmode="static" it:

    <asp:button id="buttonjq" runat="server" text="update time!" clientidmode="static"/> 

    that tells asp.net use server id client id.

  2. use else (like class) button:

    <asp:button id="buttonjq" runat="server" text="update time!" class="update-time"/> 

    then in javascript:

    $('.update-time').click(function () {     // ... }); 
  3. since javascript code in asp file, could use clientid property of button:

    $("#<% buttonjq.clientid %>").click(function() {     // ... }); 

note you'll have same issue labeljq.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -