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);
}

Put in the Page_Load event of your web page in the codebehind file. If you're using Master Pages, put it in the your child page, and not the master page, because the code in the child pages will execute before the Master page and if this is in the codebehind of Master page, you will still get the error if you're using AJAX on the child pages.

于 2008-12-13T10:26:02.020 回答
0

把它放在页面的标题部分

于 2008-09-23T23:01:26.233 回答