UserControl中的JS不适用于所有aspx页面 [英] JS in UserControl not working in all aspx pages

查看:94
本文介绍了UserControl中的JS不适用于所有aspx页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有内置js函数的usercontrol来验证其中的所有控件.usercontrols合并在3个aspx页面中,并且可以在2个aspx页面上很好地工作,但是尽管三个aspx页面都不包含任何自己的js,但它仍然可以正常工作.

每当我单击ascx文件的提交按钮时,即使我在其中写入警报,也根本不会触发js函数.它会给出错误(预期对象).

I have a usercontrol with inbuilt js functions to validate all the controls inside it.The usercontrols is incorporated in 3 aspx pages and it works fine with 2 aspx pages but one although all three aspx pages do not contain any js of their own.

Whenever i click the submit button of the ascx file the js function is not fired at all even if i write alert in it.It gives an error (Object Expected).

推荐答案

可能在第3个aspx页面中也有test()函数.请检查.
May be in 3rd aspx page there is also test() function. please check.


只需右键单击代码并查看HTML源代码,您就不会在页面上找到测试功能.如果是这种情况,则意味着您必须在第三页的页面加载时获得测试功能.它没有被加载到该页面上.

您可以通过这种方式创建测试功能
just check the code by right click and view HTML source, you wont find test function on the page. If this is the case means you have to get the test function on page load of your third page. Its not getting loaded on that page.

you can create your test function in this way
public void RegisterClientScript()
        {

            StringBuilder cstext2 = new StringBuilder();
            cstext2.Append("<script type=\"text/javascript\">  function Test() {");
            cstext2.Append("alert('Test');}");
            cstext2.Append(" </script>");
            ScriptManager.RegisterClientScriptBlock(this, GetType(), "OnClientItemSelected", cstext2.ToString(), false);
        }



并可以在第三页的页面加载时调用此方法.



and can call this method on the page load of your third page.

UcControl.RegisterClientScript();


希望它能起作用


Hope it works


这篇关于UserControl中的JS不适用于所有aspx页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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