I have a jQuery function in ASP that I am trying to get the client ID of. When It renders the HTML I get this as a result.
[HTML RENDERED]
$("")//ctl00_Content_gvProgramList
.tablesorter({ widthFixed: true, widgets: ['zebra'],
widgetOptions: {
zebra: ["even", "odd"]
}
})
.tablesorterFilter({ filterContainer: $("#filter-box"),
filterClearContainer: $("#filter-clear-button"),
filterColumns: [0, 1, 2, 3],
filterCaseSensitive: false
})
.tablesorterPager({ container: $("#pager") });
[CODE BEHIND]
$("<%# gvProgramList.ClientID %>")//ctl00_Content_gvProgramList
.tablesorter({ widthFixed: true, widgets: ['zebra'],
widgetOptions: {
zebra: ["even", "odd"]
}
})
.tablesorterFilter({ filterContainer: $("#filter-box"),
filterClearContainer: $("#filter-clear-button"),
filterColumns: [0, 1, 2, 3],
filterCaseSensitive: false
})
.tablesorterPager({ container: $("#pager") });
If i use ct100_Content_gvProgramList all the javascript works like it should, so please don’t post any answers relating to that. I want an answer on how to get the ClientID to show up correctly.
update
I would like to use $('#<%= gvProgramList.ClientID %>'), but I get an error.
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Line 16: Head.Controls.Add(Header())
Line 17: Head.Controls.Add(Menu())
Line 18: Foot.Controls.Add(Footer())
Use:
Instead of:
So:
After Update
Since you’re building/modifying the controls collection in the code-behind aspnet is barfing when you try to
Response.Write()(<%= ... %>). Try using a class name instead of the control’sid.Or:
Wrap the
<script> ... </script>inside an<asp:placeholder>. This will make the script a child of the place holder instead of the server-side control that is causing the error.