我正在尝试注册下面提到的javascript,以便与GridView一起使用,以在GridView上添加冻结功能。 在编译错误时抛出 Microsoft JScript运行时错误:'Sys'未定义
如何修复。
<script language="javascript" type="text/javascript">
// This Script is used to maintain Grid Scroll on Partial Postback
var scrollTop;
//Register Begin Request and End Request
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
//Get The Div Scroll Position
function BeginRequestHandler(sender, args)
{
var m = document.getElementById('divGrid');
scrollTop=m.scrollTop;
}
//Set The Div Scroll Position
function EndRequestHandler(sender, args)
{
var m = document.getElementById('divGrid');
m.scrollTop = scrollTop;
}
</script>
答案 0 :(得分:0)
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(initializeRequest);
prm.add_endRequest(endRequest);
var _postBackElement;</br>
function initializeRequest(sender, e)
{
if (prm.get_isInAsyncPostBack())
{ e.set_cancel(true); }
var m = document.getElementById('divGrid');
scrollTop=m.scrollTop;
}
function endRequest(sender, e)
{
var m = document.getElementById('divGrid');
m.scrollTop = scrollTop;
}
</script>
try adding the following in web.config under <system.web>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
答案 1 :(得分:0)
这是一个相当古老的帖子,但认为识别我的代码中确定的另外一件事是很重要的。简单地说,我没有特别在使用母版页时将javascript代码放在正确的位置。
这适用于我使用EnablePartialRendering =“true”的母版页中的toolkitscriptmanager
代码不完整,但应提供足够的详细信息。
<asp:content id="Content2" contentplaceholderid="ContentPlaceHolder1" runat="server">
<div>
<script type="text/javascript">
var scrolltop;
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
var elem = $get("scrollableContainer");
scrolltop = elem.scrollTop;
}
function EndRequestHandler(sender, args) {
var elem = $get("scrollableContainer");
elem.scrollTop = scrolltop;
}
</script>
<asp:updatepanel id="UpdatePanel1" runat="server" updatemode="Conditional">
<contenttemplate>
</contenttemplate>
</asp:updatepanel>
希望这有帮助!