.netajaxdebuggingstartupscriptclientscriptmanager

.net - How do you Register a startup script?


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?


Solution

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