禁用控件会导致奇怪的错误

时间:2011-11-23 09:45:35

标签: c# javascript asp.net componentart

我正在尝试在处理过程中禁用ASP.NET页面上的控件。为此,我采用了here的解决方案,运行DOM树并禁用所有子控件。这适用于我试图禁用的屏幕的许多部分,但尝试禁用一些表 - 完整的控件会产生以下错误: -

Server Error in '/' Application.
--------------------------------------------------------------------------------

Input string was not in a correct format. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 

[FormatException: Input string was not in a correct format.]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +7471479
   System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt) +115
   System.Double.Parse(String s, NumberStyles style, NumberFormatInfo info) +192
   System.Double.Parse(String s, IFormatProvider provider) +25
   ComponentArt.Web.UI.NumberInput.set_Value(Nullable`1 value) +81
   ComponentArt.Web.UI.NumberInput.LoadViewState(Object savedState) +255
   System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +183
   System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState) +134
   System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +221
   System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState) +134
   System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +221
   System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState) +134
   System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +221
   System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState) +134
   System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +221
   System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState) +134
   System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +221
   System.Web.UI.Page.LoadAllState() +312
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1661




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3625; ASP.NET Version:2.0.50727.3618 

这些都不在应用程序代码中,因此我不知道如何处理它。有谁知道如何解决问题的原因,或者我应该从哪里开始寻找?

或者,是否有更好的方法来禁用控件组?

我还尝试使用建议here建议的方法来禁用控件,方法是创建一个面板并将设置设置为false,但这似乎没有做任何事情。

编辑:根据要求,这里是用于禁用控件的Javascript:

    function disableChildElements(objId) 
    { 
        var theObject = document.getElementById(objId); 
        var level = 0; 
        TraverseDOM(theObject, level, disableElement); 
    } 

    function TraverseDOM(obj, lvl, actionFunc) 
    {  
        for (var i=0; i<obj.childNodes.length; i++)
        { 
            var childObj = obj.childNodes[i]; 

            if (childObj.tagName)
            { 
                    actionFunc(childObj); 
            } 

            TraverseDOM(childObj, lvl + 1, actionFunc); 
        } 

    } 

    function disableElement(obj) 
    { 
        obj.disabled = true; 
    } 

    function DisableControls()
    {
        disableChildElements(castVariablesTable.id);
        disableChildElements(oldGradeTable.id);
        oldGradePanel.enabled=false;
    }

DisableControls函数的第一行工作正常;第二个导致错误。用第三行替换第二行以尝试替代方法不会做任何事情。

ASP中的演员变量表就像这样......

<table id="castVariablesTable" class="normalTable">
    <tr>
        <td>
            <label class="normalText">Number of strands</label>
        </td>
        <td>
            <span class="normalInput">
                <MixedZone:NumberInput runat="server"
                                       ID="niNumberOfStrands" 
                                       MaxLength="1"
                                       Step="1"
                                       Increment="1"
                                       MaxValue="6"
                                       MinValue="1"
                                       NumberType="Number"
                                       DecimalDigits="0">
                </MixedZone:NumberInput>
            </span>

等等。

导致问题的表格太大而无法放入此处但包含相同类型的内容;我无法使用特定的控件来解决问题。

1 个答案:

答案 0 :(得分:0)

经过大量的调查后,我发现如果有人试图使用Javascript来禁用没有定义值的ComponentArt:NumberInput控件,则会阻止此错误。

在发布之前设置页面上所有ComponentArt:NumberInput控件的值可以解决错误。

相关问题