[英]Calculator Web Application Doesn't Work
Hi I need to make a calculator for school but when I click on button 1 number 1 is not coming into the textbox. 嗨,我需要为学校制作一个计算器,但是当我单击按钮1时,数字1并未出现在文本框中。
This is the aspx code I have: 这是我的aspx代码:
protected void btn1_Click(object sender, EventArgs e)
{
// controleer of er minder dan 7 tekens staan
if (txtScherm.Text.Length < 7)
{
txtScherm.Text += "1";
}
}
<asp:Table ID="Table2" runat="server">
<asp:TableRow>
<asp:TableCell><asp:TextBox runat="server" ID="txtScherm"></asp:TextBox></asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:Table ID="Table1" runat="server">
<asp:TableRow>
<asp:TableCell><asp:Button ID="btn1" runat="server" Text="7" Height="50" Width="50" /></asp:TableCell>
<asp:TableCell><asp:Button ID="btn2" runat="server" Text="8" Height="50" Width="50" /></asp:TableCell>
<asp:TableCell><asp:Button ID="btn3" runat="server" Text="9" Height="50" Width="50" /></asp:TableCell>
<asp:TableCell><asp:Button ID="btn4" runat="server" Text="C" Height="50" Width="50" /></asp:TableCell>
<asp:TableCell><asp:Button ID="btn5" runat="server" Text="Back" Height="50" Width="50" /></asp:TableCell>
</asp:TableRow>
You have to modify your code like this : 您必须像这样修改代码:
<asp:Button ID="btn1" runat="server" Text="7" Height="50" Width="50" OnClick="btn1_Click"/>
and do the same for all your buttons with the right event. 并使用正确的事件对所有按钮执行相同的操作。
You didn't set the Click Event for btn1: 您没有为btn1设置Click事件:
change: 更改:
<asp:TableCell><asp:Button ID="btn1" runat="server" Text="7" Height="50" Width="50" /></asp:TableCell>
to: 至:
<asp:TableCell><asp:Button ID="btn1" runat="server" Text="7" Height="50" Width="50" Click="btn1_Click"/></asp:TableCell>
如下所示添加OnClick =“ btn1_Click”
<asp:TableCell><asp:Button ID="btn1" runat="server" Text="7" Height="50" Width="50" OnClick="btn1_Click"/></asp:TableCell>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.