在Asyn回发中添加JavaScript [英] Add javascript on asyn postback

查看:76
本文介绍了在Asyn回发中添加JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个包含四个面板项目的面板栏.在每个面板项目中,单击我必须为该相应面板项目加载一个用户控件".加载到PageLoad上的usercontrol中的javascript可以正常工作.但是,在asyn回发中加载的usercontrol中的javascript无法正常工作,因为未加载该usercontrol中的javascript.

我的问题是如何在asyn回发中添加的usercontrol中添加javascript.

它不起作用
---->

Hi,

I have a panelbar with four panel items. In each panel item click I have to load a usercontrol for that corresponding panelitem. The javascript in usercontrol, which is loaded on PageLoad will work fine. But the javascript in the usercontrol, which is loaded in asyn postback will not work that is the javascript in that usercontrol is not loaded.

My problem is how to add the javascript in that usercontrol, which is added at asyn postback.

It is not working
---->

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "OnSelectData", "<script language='javascript' type='text/javascript'> function OnSelectData(obj,eventargs) { alert('OnSelect'); } </script>", true);



它也不起作用



It is also not working

ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "Hide", "<script language='javascript' type='text/javascript'> function OnSelectData(obj,eventargs) { alert('OnSelect'); } </script>", true);


请提供解决此问题的方法.


Please give a solution for this problem.

推荐答案

在EndRequestHandler中注册您的函数,如下所示可能对您有用...

Register you function in EndRequestHandler which as given below may work for you...

<script type="text/javascript">
        try {
                        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
        } catch (ex) { }
    </script>


function endRequestHandler() {
        /// <summary>Raised before processing of an asynchronous postback starts and the postback request is sent to the server.</summary>
               try {
              //add you function overe here
            }
        }
        catch (exeption) { }

    };


您好,函数"endRequestHandler"是JavaScript函数还是C#代码.
Hi, Whether the function "endRequestHandler" is a javascript function or C# code.


这篇关于在Asyn回发中添加JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆