如何保存在文本框中输入的数据,以后用于在单击下一个按钮时进行计算

时间:2013-09-06 15:59:54

标签: asp.net

我在面板中有一张桌子。该表有32行4列。一列是标签并有描述。其他3个是文本框。用户可以在任何文本框中输入0到99之间的数字。没有文本框是必需的,因此用户可以选择不输入任何内容。 输入完成后,用户将单击下一步按钮,计算将完成并显示在新页面中。在此之前,我想知道如何保存用户输入的所有数据。那么如何读取每个保存的行进行计算?这就是我如何使用列表int或List字符串保存在会话中以及如何计算会话中输入的数据。数据库中没有保存任何内容。 示例代码

<table class="wizard">
<tbody> 
    <tr>
      <td class="blankcell" valign="bottom" align="left" width="39%">
      <span class="smalllabel">Available Service</span></td>
      <td class="blankcell" valign="bottom" align="right" width="10%">
      <span class="smalllabel">You</span></td>
      <td class="blankcell" valign="bottom" align="right" width="10%">
      <span class="smalllabel">Spouse</span></td>
      <td class="blankcell" valign="bottom" align="right" width="10%">
      <span class="smalllabel">Child</span></td>
    </tr>
    <tr>
      <td class="grayservicebackground" align="left" valign="middle" style="width:39%;">
      <span class="servicefont">Preventive Physical Exam</span></td>
      <td id="SinglePreventivePhysicalExam" class="numberofserviceinputcell" align="right" valign="bottom" style="width:10%;">
      <asp:TextBox ID="txtSinglePreventivePhysicalExam" runat="server" value="0" maxlength="2" size="3" class="numberinput"></asp:TextBox>
      <cc2:FilteredTextBoxExtender ID="FilteredTextBoxExtender0" runat="server"
      FilterType="Numbers" TargetControlID="txtSinglePreventivePhysicalExam" />
      </td>

      <td id="SpousePreventivePhysicalExam" class="numberofserviceinputcell" align="right" valign="bottom" style="width:10%;">
      <asp:TextBox ID="txtSpousePreventivePhysicalExam" runat="server" value="0" maxlength="2" size="3" class="numberinput"></asp:TextBox>
      <cc2:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server"
      FilterType="Numbers" TargetControlID="txtSpousePreventivePhysicalExam" /></td>

      <td id="ChildPreventivePhysicalExam" class="numberofserviceinputcell" align="right" valign="bottom" style="width:10%;">
      <asp:TextBox ID="txtChildPreventivePhysicalExam" runat="server" value="0" maxlength="2" size="3" class="numberinput"></asp:TextBox>
      <cc2:FilteredTextBoxExtender ID="FilteredTextBoxExtender2" runat="server"
      FilterType="Numbers" TargetControlID="txtChildPreventivePhysicalExam" /></td>
    </tr>

    <tr>
      <td class="grayservicebackground" align="left" valign="middle" style="width:39%;">
      <span class="servicefont">Preventive Well Child Visit through Age 5</span></td>
      <td id="SinglePreventiveWellChildVisitthroughAge5" class="numberofserviceinputcell" align="right" valign="bottom" style="width:10%;">
      <asp:TextBox ID="txtSinglePreventiveWellChildVisitthroughAge5" runat="server" value="0" maxlength="2" size="3" class="numberinput"></asp:TextBox>
      <cc2:FilteredTextBoxExtender ID="FilteredTextBoxExtender3" runat="server"
      FilterType="Numbers" TargetControlID="txtSinglePreventiveWellChildVisitthroughAge5" />
      </td> 
      <td id="SpousePreventiveWellChildVisitthroughAge5" class="numberofserviceinputcell" align="right" valign="bottom" style="width:10%;">
      <asp:TextBox ID="txtSpousePreventiveWellChildVisitthroughAge5" runat="server" value="0" maxlength="2" size="3" class="numberinput"></asp:TextBox>
      <cc2:FilteredTextBoxExtender ID="FilteredTextBoxExtender4" runat="server"
      FilterType="Numbers" TargetControlID="txtSpousePreventiveWellChildVisitthroughAge5" />
      </td>
      <td id="ChildPreventiveWellChildVisitthroughAge5" class="numberofserviceinputcell" align="right" valign="bottom" style="width:10%;">
      <asp:TextBox ID="txtChildPreventiveWellChildVisitthroughAge5" runat="server" value="0" maxlength="2" size="3" class="numberinput"></asp:TextBox>
      <cc2:FilteredTextBoxExtender ID="FilteredTextBoxExtender5" runat="server"
      FilterType="Numbers" TargetControlID="txtChildPreventiveWellChildVisitthroughAge5" />
      </td> 
    </tr>
    </tbody>
 </table>

1 个答案:

答案 0 :(得分:0)

假设您正在使用ASP.NET Web Forms

如果您启用了Viewstate,则文本框将在某些情况下保留值。

你的下一个按钮会有某种与你的代码绑定的OnClick功能吗?

protected btnNext_Click(object sender, Eventargs e) {

  var value = txtSpousePreventivePhysicalExam.Text;

}

这就是你如何获得特定文本框的价值。然后,您可以将该值存储在Session中,以保持值的存活。