简体   繁体   English

使用Telerik Ajax进行模式弹出的ASP.Net服务器控件,需要禁用浏览器窗口滚动

[英]ASP.Net server control for modal popup using Telerik Ajax and need to disable browser window scrolling

I have a ASP.Net server control for modal popup and the page is using Telerik Ajax. 我有一个用于模式弹出窗口的ASP.Net服务器控件,该页面正在使用Telerik Ajax。 When the window is popped up, if you use the mouse wheel the browser window keeps on scrolling and I want to disable that. 弹出窗口时,如果使用鼠标滚轮,浏览器窗口将继续滚动,我想禁用该功能。

I tried to execute the javascript to just show an alert from the server control like below and nothing happens(really I wanted to use the commented line just after to disable browser window scrolling). 我试图执行javascript,仅显示来自服务器控件的警报,如下所示,但没有任何反应(我确实想在禁用浏览器窗口滚动之后立即使用注释行)。 The server control code is executed on postback(not on initial page load). 服务器控制代码在回发时执行(不在初始页面加载时执行)。 Not sure what else need to be done 不知道还需要做什么

protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            //register javascript here if needed
            AddScript();

        }

        private void AddScript()
        {
            ClientScriptManager csm = this.Page.ClientScript;
            string scriptblock = "<script type=\"text/javascript\">alert('hi');</script>";
            //string scriptblock = "<script type=\"text/javascript\">$(\"body\").css(\"overflow\", \"hidden\");</script>";

            string scriptname = "DisableBrowserScrollBar()";

            Type csType = this.GetType();
            if (!csm.IsClientScriptBlockRegistered(csType, scriptname))
            {
                csm.RegisterClientScriptBlock(csType, scriptname, scriptblock, false);
            }
        }

Is there a ScriptManager on your page? 您的页面上有ScriptManager吗? If so, you need to do this: 如果是这样,您需要这样做:

ScriptManager.RegisterStartupScript(Page, csType, scriptName, scriptblock, true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM