jquery controls losing styles
i have an asp.net page using a datatable jquery control to display data....the control only applies the style after i force a refresh...this might be something stupid but at the moment i am not able to figure it out. this happens in both ie and firefox...i inspected the code in firebug and cant find anything missing.... this is what i am doing...
$(document).ready(function () {
$('.datepicker').datepicker({
changeMonth: true, changeYear: true,
showOn: "both"
});
//buttons
$("button, input:submit").button();
$('#srchGrid').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"aoColumns":
[ // select columns that should not be sorted or searchable
//{ "bSortable": false, "bSearchable": false },
{ "bSortable":true},
{"bSortable":true}, // strip HTML tags before sorting this column
{ "bSortable":true},
{"bSortable":true},
{"bSortable":true},
{"bSortable":true},
{"bSortable":true},
{ "bSortable": false}
]
});
});
apparently the sty开发者_开发知识库les are being lost on postbacks....
got it....the problem is that the page is being rendered partially via a partial postback to update only the datatable....hence the initial javascript is never parsed again and since the entire page does not load the styles are lost....
to get around this....do the following....
$(function () {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args) {
$('.datepicker').datepicker({
changeMonth: true, changeYear: true,
showOn: "both"
});
// $('#grdSearchResults').single_double_click(SelectRow, DoubleClickRow);
$('#srchGrid tbody tr').dblclick(function () {
});
//buttons
$("button, input:submit").button();
$('#srchGrid').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"aoColumns":
[ // select columns that should not be sorted or searchable
//{ "bSortable": false, "bSearchable": false },
{"bSortable": true },
{ "bSortable": true }, // strip HTML tags before sorting this column
{"bSortable": true },
{ "bSortable": true },
{ "bSortable": true },
{ "bSortable": true },
{ "bSortable": true },
{ "bSortable": false }
]
});
}
});
are you setting your style inside a Document ready statement?
some thing like that:
$(function(){
//set your style where like:
$("#obj").css("color","#00FF00");
});
as your using .net, your clientID could not being rendered at the first time for some reason, try declare your selector by a different way paying attention to the rendered client id of your srchGrid object:
$("#" + <%=srchGrid.ClientID %>).dataTable({ ...
精彩评论