簡體   English   中英

用戶控件中的RegisterStartupScript不會重新加載/重寫Javascript

[英]RegisterStartupScript in User Control does not reload/ rewrite Javascript

更新

問題總結:

  1. 生成了6個動態UC,每個都有自己的自定義JS,這些JS是使用UC的Page Init上的RegisterStartUpScript注入的

  2. 僅在第一次生成第一個UC的父頁面時,腳本才會正確放置在頁面底部。

  3. 在隨后的部分更新(AJAX調用)上生成新的UC時,不會注入關聯的腳本...

我將繼續搜索並嘗試不同的方法,但是如果有人可以指導我,將不勝感激,謝謝!

以下是完整的說明

我有一個使用母版的母版頁,其中定義了RadScriptManager(Telerik的腳本管理器)。 父頁面具有一個占位符,可在其中生成動態用戶控件。 UC具有我在UC的Page_Init上注入的JavaScript。

第一次加載第一頁時,該腳本可以正常運行。.我可以在Chrome調試器的源代碼上看到它。 當我在Parent上更改ddl時,它將調用並在占位符內生成另一個UC。 后者具有自己的Javascript Inject,類似於第一個生成的...兩個UC基本上都是每個省的視圖,因此它具有相同的結構,但表單內容略有不同...

問題是,當我查看Chrome調試器時,我看到了User COntrol內容的部分更新,但是我沒有看到第二個控件中的新腳本,該腳本應該被添加到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);
}

我認為應Ajax請求,您應該使用RadAjaxPanel.ResponseScripts.Add(script)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM