JavaScript中的ASP TextBox

时间:2013-11-02 20:07:14

标签: c# java javascript jquery asp.net

我需要客户端能够将值输入到一个asp TextBox中,该文本框要求他们花费大量时间来完成这些活动。他们输入的数字在javascript中运行。我很难将这些值转换为javascript。然后按下按钮点击它。谢谢你的帮助。这是我到目前为止所得到的:

<script runat="server">

    void btn_Click(object sender, EventArgs e)
    {
        double work = double.Parse(TextBox1.Text);
        double eat = double.Parse(TextBox2.Text);
        double commute = double.Parse(TextBox3.Text);
        double tv = double.Parse(TextBox4.Text);
        double sleep = double.Parse(TextBox5.Text);
        double total = work + eat + commute + tv + sleep;
        if (total > 24)
        {
            lblmsg.Text = code();
        }
    }
    string code()
    {
        return "Warning: There are only 24 hours in a day!";
    }
</script>

Java脚本:

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
        google.load("visualization", "1", { packages: ["corechart"] });
        google.setOnLoadCallback(drawChart);
        function drawChart() {
            var work = document.getElementById('<%=TextBox1.ClientID%>').value;
            var eat = document.getElementById('<%=TextBox2.ClientID%>').value;
            var commute = document.getElementById('<%=TextBox3.ClientID%>').value;
            var tv = document.getElementById('<%=TextBox4.ClientID%>').value;
            var sleep = document.getElementById('<%=TextBox5.ClientID%>').value;
            var data = google.visualization.arrayToDataTable([
              ['Task', 'Hours per Day'],
              ['Work', work],
              ['Eat', eat],
              ['Commute', commute],
              ['Watch TV', tv],
              ['Sleep', sleep]
            ]);

            var options = {
                title: 'My Daily Activities',
                is3D: true,
            };

            var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
            chart.draw(data, options);
        }

    </script>

文本框和按钮:

Work:<asp:TextBox ID="TextBox1" runat="server" Text="11"/><asp:Label ID="lblmsg" runat="server" color="red" BackColor="red" Font-Size="XX-Large"/><br />
          Eat:<asp:TextBox ID="TextBox2" runat="server" text="2"/><br />
          Commute:<asp:TextBox ID="TextBox3" runat="server" text="2"/><br />
          Watch TV:<asp:TextBox ID="TextBox4" runat="server" text="2"/><br />
          Sleep:<asp:TextBox ID="TextBox5" runat="server" text="7"/><br />
          <asp:Button ID="btn" runat="server" Text="COMPUTE TIME" OnClick="btn_Click" />

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我想你在这里混合苹果和橘子。您不需要ASP.NET或任何其他服务器端语言来进行基本的客户端计算。单独的jQuery无论如何都可以使用简单的HTML文本框来完成它。只是学习使用jQuery val()就足够了。