2

私は、ウィザードを使用してクライアントに一連の大きな手順を実行しているASP.NET Webアプリに取り組んでいます。

手順の 1 つに、その場で一連の数値を計算することが含まれます...数値は正しく計算されますが、[次へ] をクリックしてからもう一度戻ると、一部の数値が保持されません。

計算機能はこちら

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常に BLANK に戻り、他の 3 つは常に次のように戻ります。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>

前に入力したフォームは次の
とおりです.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 に答える