7

.net の経験は限られています。私のアプリはエラー this.dateTimeFormat is undefined をスローしますが、これは既知の ajax バグにまで突き止めました。投稿された回避策は次のように述べています。

「以下を起動スクリプトとして登録します。」

Sys.CultureInfo.prototype._getAbbrMonthIndex = function(value)
{
if (!this._upperAbbrMonths) {
this._upperAbbrMonths = this._toUpperArray(this.dateTimeFormat.AbbreviatedMonthNames);
}
return Array.indexOf(this._upperAbbrMonths, this._toUpper(value));
};

では、これを行うにはどうすればよいですか?aspx ファイルの末尾にスクリプトを追加する必要がありますか?

4

3 に答える 3

9

ClientScriptManager.RegisterStartupScript()を使用します

string str = @"Sys.CultureInfo.prototype._getAbbrMonthIndex = function(value) { 
    if (!this._upperAbbrMonths) { 
        this._upperAbbrMonths = this._toUpperArray(this.dateTimeFormat.AbbreviatedMonthNames);
    }
    return Array.indexOf(this._upperAbbrMonths, this._toUpper(value));
 };";

if(!ClientScriptManager.IsStartupScriptRegistered("MyScript"){
  ClientScriptManager.RegisterStartupScript(this.GetType(), "MyScript", str, true)
}
于 2008-09-23T23:02:24.607 に答える
2

Web アプリケーションで同じ問題が発生しました (this.datetimeformat は定義されていません)。実際、これは Microsoft Ajax のバグが原因であり、この関数は MS Ajax のエラー原因関数を上書きします。

しかし、上記のコードにはいくつかの問題があります。これが正しいバージョンです。

string str = @"Sys.CultureInfo.prototype._getAbbrMonthIndex = function(value) { 
    if (!this._upperAbbrMonths) { 
        this._upperAbbrMonths = this._toUpperArray(this.dateTimeFormat.AbbreviatedMonthNames);
    }
    return Array.indexOf(this._upperAbbrMonths, this._toUpper(value));
 };";

ClientScriptManager cs = Page.ClientScript;
if(!cs.IsStartupScriptRegistered("MyScript"))
{
    cs.RegisterStartupScript(this.GetType(), "MyScript", str, true);
}

Web ページの Page_Load イベントをコード ビハインド ファイルに挿入します。マスター ページを使用している場合は、マスター ページではなく子ページに配置します。これは、子ページのコードがマスター ページの前に実行され、これがマスター ページのコード ビハインドにある場合でも取得されるためです。子ページで AJAX を使用している場合のエラー。

于 2008-12-13T10:26:02.020 に答える
0

ページのヘッダー部分に配置する

于 2008-09-23T23:01:26.233 に答える