简体   繁体   English

asp.net从后面的代码切换jquery代码

[英]asp.net toggle jquery code from code behind

I am using jquery.loadmask to mask a web page while it is pulling data like so: 我正在使用jquery.loadmask屏蔽网页,同时它提取数据是这样的:

<script type="text/javascript">
        $(document).ready(function () {
            $("#btnSubmit").bind("click", function () {
                $("#lowerContent").mask("Waiting...");
            });
        });
</script>

Once the data has been pulled I need to be able to unmask the page using this code: 提取数据后,我需要能够使用以下代码取消屏蔽页面:

        $("#lowerContent").unmask();

How can I call/inject this code from the c# code behind file so I can remove the mask? 我如何从文件后面的C#代码中调用/插入此代码,以便删除遮罩?

Ideally if I can call that from an event response. 理想情况下,我可以从事件响应中调用它。

StringBuilder sb = new StringBuilder();
sb.Append("jQuery(function($){ $(\"#lowerContent\").unmask(); }");
ClientScript.RegisterStartupScript(this.GetType(), "script", sb.ToString());

I think what you want to achieve by while working with code behind, you will get that only by using ClientScriptManager.RegisterStartupScript method. 我认为您想要通过使用背后的代码来实现的目标,只能通过使用ClientScriptManager.RegisterStartupScript方法来实现。 Or if you pull data using only ajax javascript call [NO Code-Behind call]. 或者,如果您仅使用ajax javascript调用[无代码隐藏调用]提取数据。 Because as you call code behind, your page will be postback and javascript written in document.ready() will execute. 因为当您调用后面的代码时,您的页面将被回发,并且将执行document.ready()中编写的javascript。 so you can do it. 这样就可以做到。

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

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