2

我正在开发一个 ASP.NET Web 应用程序,在该应用程序中,我使用向导引导客户端完成大量步骤。

其中一个步骤包括即时计算一堆数字……数字计算正确,但是当我单击“下一步”然后再次返回时……某些数字没有保留。

这是计算函数

function CalculateFields() {

    txtSellingPrice = document.getElementById('<%=txtSellingPrice.ClientID %>');
    //I get all of the elements like this...
    //...   

    var regexp = /[$,]/g;


    //Empty value checks
    SellingPrice = (SellingPrice == "" ? "$0" : SellingPrice);
    BalanceSheet = (BalanceSheet == "" ? "$0" : BalanceSheet);
    DownPayment = (DownPayment == "" ? "$0" : DownPayment);
    susearn = (susearn == "" ? "$0" : susearn);
    susrev = (susrev == "" ? "$0" : susrev);
    balmult = (balmult == "" ? "$0" : balmult);
    goodmult = (goodmult == "" ? "$0" : goodmult);
    sellmult = (sellmult == "" ? "$0" : sellmult);


    //Replace $ with String.Empty
    SellingPrice = txtSellingPrice.value.replace(regexp, "");
    BalanceSheet = txtBalanceSheet.value.replace(regexp, "");
    DownPayment = txtDownPayment.value.replace(regexp, "");
    susearn = txtSusEarn.value.replace(regexp, "");
    susrev = txtSusRev.value.replace(regexp, "");
    balmult = txtBalanceMult.value.replace(regexp, "");
    goodmult = txtGoodwillMult.value.replace(regexp, "");
    sellmult = txtSellingPriceMult.value.replace(regexp, "");


    //Set the new values
    txtGoodWill.value = "$" + (SellingPrice - BalanceSheet);
    txtBalance.value = "$" + (SellingPrice - DownPayment);
    txtSellingPriceMult.value = "$" + SellingPrice;
    txtGoodwillMult.value = "$" + (SellingPrice - BalanceSheet);
    txtBalanceMult.value = "$" + BalanceSheet;

    if (chkTakeBack.checked == 1) {
        txtVendorTakeBackPercentage.value = Math.round((SellingPrice - DownPayment) / SellingPrice * 100);
    }
    else {
        txtVendorTakeBackPercentage.value = "0";
    }

    if (!(susearn == "") && !(susearn == "0") && !(susearn == "$0")) {
        txtSusEarnPercentage.value = Math.round(susearn / susrev * 100);
        txtBalanceMultPercentage.value = Math.round(balmult / susearn);
        txtGoodwillMultPercentage.value = Math.round(goodmult / susearn);
        txtSellingPriceMultPercentage.value = Math.round(sellmult / susearn);
    }
    else {
        txtSusEarnPercentage.value = "0";
        txtBalanceMultPercentage.value = "0";
        txtGoodwillMultPercentage.value = "0";
        txtSellingPriceMultPercentage.value = "0";
    }

}

所有这些都正确计算并在回发中保留其价值

    txtGoodWill.value = "$" + (SellingPrice - BalanceSheet);
    txtBalance.value = "$" + (SellingPrice - DownPayment);
    txtSellingPriceMult.value = "$" + SellingPrice;
    txtGoodwillMult.value = "$" + (SellingPrice - BalanceSheet);
    txtBalanceMult.value = "$" + BalanceSheet;

然而,这些并没有在回发中保留它们的价值

        if (chkTakeBack.checked == 1) {
            txtVendorTakeBackPercentage.value = Math.round((SellingPrice - DownPayment) / SellingPrice * 100);
        }
        else {
            txtVendorTakeBackPercentage.value = "0";
        }

        if (!(susearn == "") && !(susearn == "0") && !(susearn == "$0")) {
            txtSusEarnPercentage.value = Math.round(susearn / susrev * 100);
            txtBalanceMultPercentage.value = Math.round(balmult / susearn);
            txtGoodwillMultPercentage.value = Math.round(goodmult / susearn);
            txtSellingPriceMultPercentage.value = Math.round(sellmult / susearn);
        }
        else {
            txtSusEarnPercentage.value = "0";
            txtBalanceMultPercentage.value = "0";
            txtGoodwillMultPercentage.value = "0";
            txtSellingPriceMultPercentage.value = "0";
        }

txtVendorTakeBackPercentage总是返回空白,其他三个总是作为0

我通过使用onkeyup表单字段中的事件来触发这些功能。

    If Not Page.IsPostBack Then
        txtSellingPrice.Attributes.Add("onkeyup", "CalculateFields()")
        txtBalanceSheet.Attributes.Add("onkeyup", "CalculateFields()")
        txtDownPayment.Attributes.Add("onkeyup", "CalculateFields()")
        txtSusRev.Attributes.Add("onkeyup", "CalculateFields()")
        txtSusEarn.Attributes.Add("onkeyup", "CalculateFields()")
    End If

任何想法/帮助/方向将不胜感激。

编辑:
我的页面加载事件看起来像这样......

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load


    'Prepair page for advanced validation'
    Dim cs As ClientScriptManager = Page.ClientScript
    If Not cs.IsOnSubmitStatementRegistered(Me.[GetType](), "PrepareValidationSummary") Then _
        cs.RegisterOnSubmitStatement(Me.[GetType](), "PrepareValidationSummary", "CheckForm()")

    If Not Page.IsPostBack Then

        'Part of the client side math'
        txtSellingPrice.Attributes.Add("onkeyup", "CalculateFields()")
        txtBalanceSheet.Attributes.Add("onkeyup", "CalculateFields()")
        txtDownPayment.Attributes.Add("onkeyup", "CalculateFields()")
        txtSusRev.Attributes.Add("onkeyup", "CalculateFields()")
        txtSusEarn.Attributes.Add("onkeyup", "CalculateFields()")

我实际的 aspx 页面有超过 2400 行,所以我不会发布整个内容。这是百分比字段未保留其值的部分。

  <tr>
                        <td colspan="5" class="AlignRight">
                            Average Annual Sustainable Earnings (ebitda) estimated&nbsp;
                            <ew:NumericBox ID="txtSusEarnPercentage" runat="server" Enabled="False" MaxLength="3"
                                Width="20px" TruncateLeadingZeros="True" />
                            %
                        </td>
                        <td class="AlignRight">
                            <ew:NumericBox ID="txtSusEarn" runat="server" AutoFormatCurrency="True" DecimalPlaces="2"
                                MaxLength="9" Width="92px" />
                        </td>
                        <td>
                            <asp:Image ID="HelpEBITDA0" runat="server" Height="16px" ImageUrl="~/Images/Icons/help.gif" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="5" class="AlignRight">
                            &nbsp;
                        </td>
                        <td class="AlignRight">
                            &nbsp;
                        </td>
                        <td>
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <td colspan="5" class="AlignRight">
                            Balance Sheet / Net Asset Value as earnings multiple&nbsp;&nbsp;
                            <ew:NumericBox ID="txtBalanceMultPercentage" runat="server" Enabled="False" MaxLength="3"
                                Width="20px" />
                        </td>
                        <td class="AlignRight">
                            <ew:NumericBox ID="txtBalanceMult" runat="server" AutoFormatCurrency="True" DecimalPlaces="2"
                                MaxLength="9" Width="92px" Enabled="False" />
                        </td>
                        <td>
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <td colspan="5" class="AlignRight">
                            Goodwill Value as earnings multiple&nbsp;&nbsp;
                            <ew:NumericBox ID="txtGoodwillMultPercentage" runat="server" Enabled="False" MaxLength="3"
                                Width="20px" />
                        </td>
                        <td class="AlignRight">
                            <ew:NumericBox ID="txtGoodwillMult" runat="server" AutoFormatCurrency="True" DecimalPlaces="2"
                                MaxLength="9" Width="92px" Enabled="False" />
                        </td>
                        <td>
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <td colspan="5" class="AlignRight">
                            Proposed Selling Price as earnings multiple&nbsp;&nbsp;
                            <ew:NumericBox ID="txtSellingPriceMultPercentage" runat="server" Enabled="False"
                                MaxLength="3" Width="20px" />
                        </td>
                        <td class="AlignRight">
                            <ew:NumericBox ID="txtSellingPriceMult" runat="server" AutoFormatCurrency="True"
                                DecimalPlaces="2" MaxLength="9" Width="92px" Enabled="False" />
                        </td>
                        <td>
                            &nbsp;
                        </td>
                    </tr>

这是我填写时的表格
before.png

这是我点击“下一个”然后点击“上一个”之后的表格
after.png

编辑

图片早就没了,抱歉。

4

1 回答 1

1

asp.net 不维护只读或禁用文本框的值...以解决此使用:

TextBox1.Attributes.Add("readonly","readonly");代替TextBox1.ReadOnly = true;

TextBox1.Attributes.Add("disabled","disabled");代替TextBox1.Enabled = false;

让我知道这是否可以解决您的问题。

于 2010-05-25T20:38:27.950 回答