1

更新

问题总结:

  1. 生成了 6 个动态 UC,每个都有自己的自定义 JS,这些 JS 使用 UC 的 Page Init 上的 RegisterStartUpScript 注入

  2. 只有第一次生成第一个 UC 的父页面才会将脚本正确放置在页面底部。

  3. 在后续的部分更新(AJAX 调用)以生成新的 UC 时,不会注入相关的脚本......

我会继续搜索并尝试不同的东西,但如果有人可以指导我,将不胜感激谢谢!

下面是完整的解释

我有一个使用 Master 的父页面,其中定义了 RadScriptManager(telerik 的脚本管理器)。父页面有一个占位符,其中生成了一个动态用户控件。UC 有一个我在 UC 的 Page_Init 上注入的 javascript。

当我第一次调用它时,第一页加载,脚本正常工作。我可以在 Chrome 调试器的源代码中看到它。当我在 Parent 上更改 ddl 时,它会调用并在占位符内生成另一个 UC。后者有自己的 Javascript Inject,类似于生成的第一个...两个 UC 基本上都是每个省的 View,因此结构相同,但表单内容略有不同...

问题是,当我查看 Chrome 调试器时,我看到了用户控件内容的部分更新,但我没有看到来自第二个控件的新脚本,该脚本应该添加到 UC 的 Page_Init 上的 add_load 中。所以每次,我改变控制,它调用以前的脚本......虽然我的代码通过下面的部分......这基本上是为正在加载的给定控件注册适当的脚本。

在下面的示例中,我总是看到警报“SK cmbSearch = ..”,而不是“ON cmbSearch = ...”,这是我试图加载的当前省份。

谁能给我一些指示?

public void RegisterSearchVisibilityPPSA()
{
string jsFunction =
@"function DefineView(sender, eventArgs) {
    var comboSearch = $find('%%cmbSearchType%%');
    //cmbSearch Section
    alert('ON cmbSearch = %%cmbSearchType%% with value = ' + comboSearch.get_selectedItem().get_value() );
    switch (comboSearch.get_selectedItem().get_value()) {
        //PER 
        case 'IN':
        case 'IS' :
            $('#tblPersonSearchForm').show();
            $('#tblPersonDOBSearchForm').show();
            $('#tblBusinessSearchForm').hide();
            $('#tblSerialNumberedSearchForm').hide();
            break;
        //BUS 
        case 'BD':
            $('#tblPersonSearchForm').hide();
            $('#tblPersonDOBSearchForm').hide();
            $('#tblBusinessSearchForm').show();
            $('#tblSerialNumberedSearchForm').hide();
            break;
        //SER 
        case 'MVE':
        case 'MVS':
            $('#tblPersonSearchForm').hide();
            $('#tblPersonDOBSearchForm').hide();
            $('#tblBusinessSearchForm').hide();
            $('#tblSerialNumberedSearchForm').show();
            break;
        //REG 
        case 'REG':
        default:
            $('#tblPersonSearchForm').hide();
            $('#tblPersonDOBSearchForm').hide();
            $('#tblBusinessSearchForm').hide();
            $('#tblSerialNumberedSearchForm').hide();
            $('#tblRegistrationNumberedSearchForm').show();
            break;
    }


}

function onPageLoad(){
    // jquery Area
    $(document).ready(function () {
        DefineView();
    });
}
";


RadScriptManager.RegisterStartupScript(this, this.GetType(), "ON_SearchVisibilityPPSA",jsFunction.Replace("%%cmbSearchType%%", cmbSearchType.ClientID), cmbRegistrationType.ClientID), true);
string onLoadScript = @" Sys.Application.add_load(function(){ onPageLoad();}) ";
RadScriptManager.RegisterStartupScript(this, this.GetType(), "ON_onLoadScript", onLoadScript, true);
}
4

1 回答 1

0

根据 Ajax 请求,我认为您应该使用 RadAjaxPanel.ResponseScripts.Add(script)。

于 2013-05-07T17:29:55.170 回答