.net-如何注册启动脚本?

.net-如何注册启动脚本?,.net,ajax,debugging,startupscript,clientscriptmanager,.net,Ajax,Debugging,Startupscript,Clientscriptmanager,我在.net方面的经验有限。我的应用程序在此抛出一个错误。dateTimeFormat未定义,我跟踪到一个已知的ajax错误。发布的解决方案说: “将以下内容注册为启动脚本:” 那我该怎么做呢?是否将脚本添加到我的aspx文件的底部?将其放在您将使用的页面的页眉部分 我在web应用程序中也遇到了同样的问题(this.datetimeformat未定义),事实上,这是由于Microsoft Ajax中的一个错误造成的,该函数超越了MS Ajax中的错误导致函数 但是上面的代码有一些问题。这是正确的

我在.net方面的经验有限。我的应用程序在此抛出一个错误。dateTimeFormat未定义,我跟踪到一个已知的ajax错误。发布的解决方案说:

“将以下内容注册为启动脚本:”


那我该怎么做呢?是否将脚本添加到我的aspx文件的底部?

将其放在您将使用的页面的页眉部分


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

将网页的页面加载事件放入代码隐藏文件中。如果您使用的是母版页,请将其放在您的子页中,而不是母版页中,因为子页中的代码将在母版页之前执行,如果这是在母版页的代码隐藏中,如果您在子页上使用AJAX,您仍然会收到错误。

那么,我会将javascript放在标题中吗?我是否需要在一个名为“myscript”的函数中包装“string str=…”?不,您只需在代码隐藏中添加此代码,很可能是在页面加载方法中。“MyScript”只是一个名称,因此您可以检查该特定脚本是否已加载。上面的代码是用C语言编写的,我会把它放在一个外部文件中。这里没有需要内联的内容。
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)
}
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);
}