我在我的 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.