问题描述
即使我在后面的代码上进行脚本注册后,执行异步回发页时也会丢失gridviewscroll脚本.(我在更新面板中有网格.在asp.net网格视图中单击添加新行"时会发生这种情况.)
While doing asynchronous postback page losings gridviewscroll script even after i did script register on code behind. (I have grid in update panel.. This happen when clicking "add new row" in asp.net grid view.)
我尝试了以下三种方法.
I have tried with the following three methods.
ScriptManager.RegisterStartupScript(UpdatePanel_Objective, this.GetType(), UpdatePanel_Objective.UniqueID, "gridviewScroll();", true);
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "gridviewScroll();", true);
StringBuilder sb = new StringBuilder();
sb.Append("<script src='js/jquery-1.11.1.min.js'></script>");
sb.Append("<script src='js/jquery-ui.min.js'></script>");
sb.Append("<script src='js/gridviewScroll.min.js'></script>");
sb.Append("<script src='js/gridviewScroll.js'></script>");
sb.Append("<script type = 'text/javascript'>");
sb.Append("$('#<%=Objective.ClientID%>').gridviewScroll({height: 500,freezesize: 2,headerrowcount: 2});");
sb.Append("</script>");
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", sb.ToString(), true);
以上所有方法均无效.请指教.谢谢.
None of the above is worked. Please advise. Thanks.
推荐答案
即使在异步回发之后,也需要再次触发 gridviewScroll
.即使您看不到它,UI也会更新,并且所有使用jQuery进行的绑定都将丢失并且必须重新绑定.因此,请使用 EndRequest
功能.
You need to trigger gridviewScroll
again, even after an async PostBack. Even if you do not see it, the UI is updated and all bindings made with jQuery are lost and have to be rebound. So use the EndRequest
functionality.
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function () {
createGridviewScroll()
});
$(document).ready(function () {
createGridviewScroll();
});
function createGridviewScroll() {
//do your thing
}
</script>
执行此 sb.Append("$('#<%= Objective.ClientID%>')
"的PS不会做太多事情,因为您将无法以这种方式获取正确的ClientID.使用
PS doing this sb.Append("$('#<%=Objective.ClientID%>')
does not do much because you won't get the correct ClientID that way. Use
sb.Append("$('#" + Objective.ClientID + "').gridviewScroll({height: 500,freezesize: 2,headerrowcount: 2});");
这篇关于在执行异步回发页面时丢失了gridviewscroll脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!