سؤال

لدي خبرة محدودة مع .net.يُظهر تطبيقي خطأ this.dateTimeFormat غير محدد والذي قمت بتتبعه حتى وصل إلى خطأ معروف في أجاكس.قال الحل البديل المنشور لـ:

"قم بتسجيل ما يلي كبرنامج نصي لبدء التشغيل:"

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 الخاص بي؟

هل كانت مفيدة؟

المحلول

سوف تستخدم 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)
}

نصائح أخرى

لقد واجهت نفس المشكلة في تطبيق الويب الخاص بي (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);
}

ضع حدث Page_Load الخاص بصفحة الويب الخاصة بك في ملف codebehind.إذا كنت تستخدم الصفحات الرئيسية، فضعها في صفحتك الفرعية، وليس الصفحة الرئيسية، لأن التعليمات البرمجية الموجودة في الصفحات الفرعية سيتم تنفيذها قبل الصفحة الرئيسية، وإذا كان هذا موجودًا في التعليمات البرمجية الموجودة خلف الصفحة الرئيسية، فستظل تحصل على الخطأ إذا كنت تستخدم AJAX على الصفحات الفرعية.

ضعه في الجزء العلوي من الصفحة

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top