<%@ Page Title="" Language="C#" MasterPageFile="MasterPageStock.master" AutoEventWireup="true" CodeFile="SignInGrid.aspx.cs" Inherits="SignInGrid" %>
<asp:Content ID="Content0" ContentPlaceHolderID="head" runat="Server">
<style type="text/css">
td.details-control {
background: url('Images/bullet_add.png') no-repeat center center;
cursor: pointer;
}
tr.shown td.details-control {
background: url('Images/red_minus.png') no-repeat center center;
}
.navbar-right {
display: block;
}
.lnkBtnLogOut, .pageTitle {
display: inline;
}
.rwBtn {
margin: 30px 0 0 0;
}
</style>
<script type="text/javascript">
//MYSQL DB VERSION
$(document).ready(function () {
$.ajax({
"url": "SignInGrid.aspx/getData",
"type": "POST",
"contentType": "application/json; charset=utf-8",
"dataType": "json",
success: function (json) {
var table = $('#example').DataTable({
"columns": [
{
"targets": 0,
"data": "StudentID",
"render": function (data, type, full, meta, oData) {
return '<a href="StudentAthleteInfo.aspx?StudentID=' + data + '">' + data + '</a>';
}
},
{ "data": "StudentName" },
{ "data": "TimeIn" },
{ "data": "TimeSignedIn" },
{
"targets": -1,
"data": null,
"defaultContent": "<button>Week Total</button>"
},
{
"targets": -1,
"data": null,
"defaultContent": "<button>Sign Out</button>"
},
],
"aaData": $.parseJSON(json.d)
});
}
});
var lblVal = $(".userIDLabel").html();
var lblVal1 = $(".dealerTypeLabel").html();
if (lblVal.indexOf("ADMIN") >= 0) {
$(".adminLinks").css("display", "block");
$("#liViewVendorSubmissions").css("display", "block");
$("#liVendorList").css("display", "none");
$("#topdropdown").css("display", "none");
$("#liSearchInvintoryMenuItem").css("display", "none");
$("#liRequstBoardMenuItem").css("display", "none");
$("#liProfileMenuItem").css("display", "none");
$("#liContactUsMenuItem").css("display", "none");
}
else {
$(".adminLinks").css("display", "none");
}
});
</script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="Server">
<div class="row myRow">
<div class="col-lg-12 text-page-title-center" style="background: #000; height: 33px;">
<div id="divPageTitle" class="center-page-title center" runat="server">
<asp:Label class="pageTitle" runat="server" ID="pageTitle" Text="SIGNED IN LIST"></asp:Label>
</div>
</div>
</div>
<table id="example" class="display responsive nowrap" data-page-length="5" width="100%" cellspacing="0">
<thead>
<tr>
<th data-orderable="true">StudentID</th>
<th data-orderable="true">StudentName</th>
<th data-orderable="true">TimeIn</th>
<th data-orderble="true">TimeSignedIn</th>
<th>Week Total</th>
<th>Sign Out</th>
<%--<th>Delete</th>--%>
</tr>
</thead>
</table>
</asp:Content>
myScreen.jpg
(function(){
var btns = document.querySelectorAll("input");
for(var i = 0; i < btns.length; i++){
var btn = btns[i];
btn.addEventListener("click", function(){
var url = this.getAttribute("data-url");
window.location = url;
});
}
})();
btn.addEventListener("click", function(){
var url = this.getAttribute("data-url");
window.location = url;
});
{
"targets": -1,
"data": null,
"defaultContent": "<button id='btnWeekTotal' data-url='SignInGrid.aspx?getweektotal=y'>Week Total</button>"
},
$("#btnWeekTotal").addEventListener("click", function () {
var url = this.getAttribute("data-url");
window.location = url;
});
$("#btnWeekTotal").click (function () {
var url = this.getAttribute("data-url");
window.location = url;
});
$("#btnWeekTotal").on("click" (function () {
var url = this.getAttribute("data-url");
window.location = url;
});
.
.
.
{
"targets": -1,
"data": null,
"defaultContent": "<button id='btnWeekTotal'data-
url='SignInGrid.aspx?getweektotal=y'>Week Total</button>"
},
.
.
$(document).on('click', '#btnWeekTotal', function () { <--i stop the debugger here
var url = this.getAttribute("data-url");
window.location = url;
}); <--when I step through it skips the code in the middle and lands here, why?
$(document).click('#btnWeekTotal', function () { <--i stop the debugger here
var url = this.getAttribute("data-url");
window.location = url;
}); <--when I step through it skips the code in the middle and lands here, why?
<script type="text/javascript">
//MYSQL DB VERSION
$(document).ready(function () {
$.ajax({
"url": "SignInGrid.aspx/getData",
"type": "POST",
"contentType": "application/json; charset=utf-8",
"dataType": "json",
success: function (json) {
var table = $('#example').DataTable({
"columns": [
{
"targets": 0,
"data": "StudentID",
"render": function (data, type, full, meta, oData) {
return '<a href="StudentAthleteInfo.aspx?StudentID=' + data + '">' + data + '</a>';
}
},
{ "data": "StudentName" },
{ "data": "TimeIn" },
{ "data": "TimeSignedIn" },
{
"targets": -1,
"data": null,
"defaultContent": "<button id='btnWeekTotal' data-url='SignInGrid.aspx?getweektotal='>Week Total</button>"
},
{
"targets": -1,
"data": null,
"defaultContent": "<button>Sign Out</button>"
},
],
"aaData": $.parseJSON(json.d)
});
}
});
var lblVal = $(".userIDLabel").html();
var lblVal1 = $(".dealerTypeLabel").html();
if (lblVal.indexOf("ADMIN") >= 0) {
$(".adminLinks").css("display", "block");
$("#liViewVendorSubmissions").css("display", "block");
$("#liVendorList").css("display", "none");
$("#topdropdown").css("display", "none");
$("#liSearchInvintoryMenuItem").css("display", "none");
$("#liRequstBoardMenuItem").css("display", "none");
$("#liProfileMenuItem").css("display", "none");
$("#liContactUsMenuItem").css("display", "none");
}
else {
$(".adminLinks").css("display", "none");
}
});
$(document).on('click', '#btnWeekTotal', function () {
var url = this.getAttribute("data-url");
window.location = url;
});
</script>
First thing you can find those buttons/links you have added in your table (may be by id/class/traversing)
After that you can use .on() method to attach (any) event on that element (buttons).
Note: this .on() is available on jQuery 1.8 above. for earlier version (1.7) you can use .live() and before that you can use delegates
$( selector ).live( events, data, handler ); // jQuery 1.3+
$( document ).delegate( selector, events, data, handler ); // jQuery 1.4.3+
$( document ).on( events, selector, data, handler ); // jQuery 1.7+
Source: http://api.jquery.com/live/
Hope this helps you.