.net - 如何注册启动脚本? [英] .net - How do you Register a startup script?

查看:180
本文介绍了.net - 如何注册启动脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对.net的经验有限。我的应用程序抛出一个错误this.dateTimeFormat是未定义的,我追踪到一个已知的ajax错误。发布的解决方法说:



注册以下作为启动脚本:

 code> Sys.CultureInfo.prototype._getAbbrMonthIndex = function(value)
{
if(!this._upperAbbrMonths){
this._upperAbbrMonths = this._toUpperArray(this.dateTimeFormat。缩写的蒙特尼姆);
}
return Array.indexOf(this._upperAbbrMonths,this._toUpper(value));
};

那么我该怎么办?我将脚本添加到我的aspx文件的底部?

解决方案

您将使用 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)
}


I have limited experience with .net. My app throws an error this.dateTimeFormat is undefined which I tracked down to a known ajax bug. The workaround posted said to:

"Register the following as a startup script:"

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

So how do I do this? Do I add the script to the bottom of my aspx file?

解决方案

You would use 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)
}

这篇关于.net - 如何注册启动脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆